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 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() ...

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