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

This exercise simulates the realization of an exam that has three exercises. All the students have to finish one exercise before they can start the next one. To implement this synchronization requirement, we use the Phaser class; however, in this case, you implemented your own phaser, extending the original class to override the onAdvance() method.

This method is called by Phaser before making a phase change and waking up all the threads that were sleeping in the arriveAndAwaitAdvance() method. The method is invoked by the last thread that finishes a phase as part of the code of the arriveAndAwaitAdvance() method. This method receives the number of the actual phase as parameters, where 0 is the number of the first phase and ...

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