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

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

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