In Java 8 there are two ways of starting asynchronous computations - CompletableFuture
and ForkJoinTask
. They both seem fairly similar - the inner classes of CompletableFuture
even extend ForkJoinTask
.
Is there a reason to use one over the other?
One key difference that I can see is that the CompletableFuture.join
method simply blocks until the future is complete (waitingGet
just spins using a ManagedBlocker
), whereas a ForkJoinTask.join
can steal work off the queue to help the task you're joining on to complete.
Is there a benefit over one or the other?