How to do it...

Follow these steps to implement the example:

  1. Create a class named MyWorkerTask and specify that it extends the ForkJoinTask class parameterized by the Void type:
        public abstract class MyWorkerTask extends ForkJoinTask<Void> {
  1. Declare a private String attribute called name to store the name of the task:
        private String name;
  1. Implement the constructor of the class to initialize its attribute:
        public MyWorkerTask(String name) { ;         }
  1. Implement the getRawResult() method. This is one of the abstract methods of the ForkJoinTask class. As the MyWorkerTask tasks won't return any results, this method must return null:
        @Override         public Void getRawResult() {           return null;         }
  1. Implement the setRawResult() ...

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.