Ok, so I know the first answer / comment here will be "use one ExecutorService
and use invokeAll
". However, there is a good reason (which I will not bore people with) for us keeping the thread pools separate.
So I have a list of thread pools (ExecutorServices
) and what I need to do is invoke a different Callable
on each thread pool using submit
(no problem there). Now I have this collection of Future
instances, each created on a seperate ExecutorService
, and I want to wait for all of them to complete (and be able to provide a timeout at which any not done are cancelled).
Is there an existing class that will do this (wrap a list of Future
instances and allow for a wait till all are done)? If not, suggestions on an efficient mechanism would be appreciated.
Was thinking of calling get
with a timeout for each but have to do a calculation of the total time passed for each call.
I saw this post Wait Until Any of Future is Done but this extends Future
instead of wrapping a list of them.
ListeningExecutorService
s... – UpholstererExecutorServices
– FlavoryFutures
are produces using a set of services (not a single executor service) – FlavoryMoreExecutors.listeningDecorator(service)
, you can turn them all intoListeningExecutorService
s. Then you could doFutures.allAsList
to create a "joined" future. – Upholsterer