I have a set of Futures
created by submitting Callable
s to an Executor
. Pseudo code:
for all tasks
futures.add(executor.submit(new callable(task)))
Now I'd like to get all futures waiting at most n seconds until all complete. I know I can call Future#get(timeout)
but if I call that sequentially for all my futures in a loop the timouts start adding up. Pseudo code:
for all futures
future.get(timeout)
get
blocks with a timeout until the result is ready. Therefore, if the first completes just before timeout and the second also completes just before timeout and so on the entire execution time is number of futures * timeout
at most instead of timeout
.
Hence, I'm looking for a method that accepts a list of Future
s and a timeout, runs all in parallel and then returns a collection of future results. Any ideas?