Is it possible to timeout a task when using ThreadPoolTaskExecutor
? I cannot change the ThreadPoolTaskExecutor
to ThreadPoolExecutor
or to ExecutorService
.
Is it possible to timeout a task when using ThreadPoolTaskExecutor
? I cannot change the ThreadPoolTaskExecutor
to ThreadPoolExecutor
or to ExecutorService
.
After submitting a Callable
to your ThreadPoolTaskExecutor
you should get a Future
. And on this Future
, you can call the get(long timeout, TimeUnit unit)
function with a TimeUnit
, which is the timeout, the maximum time the program will wait until either the future delivers or moves on, by throwing a TimeoutException
.
ie (unconfirmed pseudocode)
Future myFuture = threadPoolTaskExecutor.submit(myCallable);
try {
myResult = myFuture.get(5l,TimeUnit.SECONDS);
} catch(TimeoutException e) {
// Timeout-Related stuff here
}