There's more...

In this example, you used the join() method to wait for the finalization of tasks and get their results. You can also use one of the following two versions of the get() method with this purpose:

  • get(): This version of the get() method returns the value returned by the compute() method if ForkJoinTask has finished its execution, or it waits until its finalization.
  • get(long timeout, TimeUnit unit): This version of the get() method, if the result of the task isn't available, waits the specified time for it. If the specified period of time passes and the result isn't yet available, the method returns a null value. The TimeUnit class is an enumeration with the following constants: DAYS, HOURS, MICROSECONDS, MILLISECONDS, MINUTES ...

Get Java 9 Concurrency Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.