How it works...

In this recipe, we implemented a phased task in the Task class. This phased task has three phases and uses a Phaser interface to synchronize with other Task objects. The main class launches three tasks, and when these tasks execute their respective phases, it prints information about the status of the phaser object to the console. We used the following methods to get the status of the phaser object:

  • getPhase(): This method returns the actual phase of a phaser object
  • getRegisteredParties(): This method returns the number of tasks that use a phaser object as a mechanism of synchronization
  • getArrivedParties(): This method returns the number of tasks that have arrived at the end of the actual phase
  • getUnarrivedParties(): This ...

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.