As per Oracle documentation :
invokeAll()
: Executes the given tasks, returning a list of Futures holding their status and results when all complete.Future.isDone()
is true for each element of the returned list. 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.
CompletableFuture
also implements Future with the following policies:
Since (unlike
FutureTask
) this class has no direct control over the computation that causes it to be completed, cancellation is treated as just another form of exceptional completion. Method cancel has the same effect ascompleteExceptionally(new CancellationException())
. MethodisCompletedExceptionally()
can be used to determine if aCompletableFuture
completed in any exceptional fashion.In case of exceptional completion with a
CompletionException
, methodsget()
andget(long, TimeUnit)
throw anExecutionException
with the same cause as held in the correspondingCompletionException
. To simplify usage in most contexts, this class also defines methodsjoin()
andgetNow(T)
that instead throw theCompletionException
directly in these cases.
What are the differences between
invokeAll()
withFuture
CompletableFuture
Since JDK 1.7 does not support CompletableFuture
, can the same result will be achieved with invokeAll()
with Future
?