How to do it...

Follow these steps to implement the example:

  1. Create a class named MyWorkerThread that extends the ForkJoinWorkerThread class:
        public class MyWorkerThread extends ForkJoinWorkerThread {
  1. Declare and create a private ThreadLocal attribute parameterized by the Integer class named taskCounter:
        private final static ThreadLocal<Integer> taskCounter=                                         new ThreadLocal<Integer>();
  1. Implement a constructor of the class:
        protected MyWorkerThread(ForkJoinPool pool) {           super(pool);         }
  1. 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 ...

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.