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

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.