Follow these steps to implement the example:
- Create a class named MyWorkerThread that extends the ForkJoinWorkerThread class:
public class MyWorkerThread extends ForkJoinWorkerThread {
- Declare and create a private ThreadLocal attribute parameterized by the Integer class named taskCounter:
private final static ThreadLocal<Integer> taskCounter= new ThreadLocal<Integer>();
- Implement a constructor of the class:
protected MyWorkerThread(ForkJoinPool pool) { super(pool); }
- Override the onStart() method. Call the method on its parent class, print a message to the console, and set the value of the taskCounter attribute of this thread to zero:
@Override protected void onStart() { super.onStart(); System.out.printf("MyWorkerThread ...