How it works...
Threads used by the fork/join framework are called worker threads. Java includes the ForkJoinWorkerThread class that extends the Thread class and implements the worker threads used by the fork/join framework.
In this recipe, you implemented the MyWorkerThread class that extends the ForkJoinWorkerThread class and overrides two methods of the ForkJoinWorkerThread class. Your objective is to implement a counter of tasks in each worker thread so that you can know how many tasks a worker thread has executed. You implemented the counter with a ThreadLocal attribute. This way, each thread will have its own counter in a transparent way for you, the programmer.
You overrode the onStart() method of the ForkJoinWorkerThread class to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access