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

Forcing the termination of Phaser

When phaser has zero participants, it enters a state denoted by termination. The Phaser class provides forceTermination() to change the status of phaser and makes it enter the termination state independently of the number of participants registered in phaser. This mechanism may be useful when one of the participants has an error situation, where the best thing to do would be to terminate phaser.

When phaser is in the termination state, the awaitAdvance() and arriveAndAwaitAdvance() methods immediately return a negative number, instead of a positive one that is returned normally. If you know that your phaser could be terminated, you should verify the return value of those methods (awaitAdvance() and arriveAndAwaitAdvance() ...

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