O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required