Follow these steps to implement the example:
- 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> {
- Declare a private String attribute called name to store the name of the task:
private String name;
- Implement the constructor of the class to initialize its attribute:
public MyWorkerTask(String name) { this.name=name; }
- 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; }
- Implement the setRawResult() ...