How to do it...

Follow these steps to implement the example:

  1. Create a class named MyPhaser and specify that it extends from the Phaser class:
        public class MyPhaser extends Phaser {
  1. Override the onAdvance() method. According to the value of the phase attribute, we call it a different auxiliary method. If the phase attribute is equal to zero, you have to call the studentsArrived() method. If the phase is equal to one, you have to call the finishFirstExercise() method. If the phase is equal to two, you have to call the finishSecondExercise() method. Finally, if the phase is equal to three, you have to call the finishExam() method. Otherwise, return the true value to indicate that phaser has terminated:
        @Override  protected boolean onAdvance(int ...

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.