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

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.