O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

In this recipe, you implemented the MyWorkerTask class that extends the ForkJoinTask class. It's your own base class to implement tasks that can be executed in a ForkJoinPool executor and that can take advantage of all the benefits of the executor, as it's a work-stealing algorithm. This class is equivalent to the RecursiveAction and RecursiveTask classes.

When you extend the ForkJoinTask class, you have to implement the following three methods:

  • setRawResult(): This method is used to establish the result of the task. As your tasks don't return any results, leave this method empty.
  • getRawResult(): This method is used to return the result of the task. As your tasks don't return any results, this method returns null.
  • exec() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required