How to do it...

All computations are encapsulated inside a subclass of one of the two subclasses (RecursiveAction or RecursiveTask<T>of the abstract ForkJoinTask class. You can extend either RecursiveAction (and implement the void compute() method) or RecursiveTask<T> (and implement the T compute() method). As you may have noticed, you can choose to extend the RecursiveAction class for tasks that do not return any value, and extend RecursiveTask<T> when you need your tasks to return a value. In our demo, we are going to use the latter because it is slightly more complex.

Let's say we would like to calculate the average speed of traffic in a certain location on a certain date and time and driving conditions (all these parameters are defined ...

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.