karephul
karephul

Reputation: 1483

Remaining tasks of Executor Service after timeout

When timeout occurs I know that the callable tasks that are currently running on those five threads will be interrupted. What happens to the remaining 10 tasks?

Looks like the remaining tasks are just removed from the internal tasks queue. I cannot find documentation which explains this in detail.

ExecutorService service = Executors.newFixedthreadPoolExecutor(5);
List<Callable> tasks = getTasks(15); // create 15 tasks which takes 2 second each.
service.invokeAll(tasks, 500, TimUnit.MILLISECONDS);
// let's move on.

Upvotes: 0

Views: 444

Answers (1)

Start0101End
Start0101End

Reputation: 108

As per Java Doc for ExecutorService method invokeAll():

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html

<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
                        long timeout,
                        TimeUnit unit)
                      throws InterruptedException

Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first. Future.isDone() is true for each element of the returned list. Upon return, tasks that have not completed are cancelled. Note that a completed task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.

Upvotes: 1

Related Questions