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) {           this.name=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 O’Reilly online learning.

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