The Java Phaser Class
Using synchronization class
Phaser you can define a synchronization object that waits until a specific phase has completed. It then advances to the next phase, again waiting until that phase concludes.
- It creates a new phaser having no registered parties.
- Phaser(int numberOfParties)
- It creates a new phaser having numberOfParties registered unarrived parties.
- Phaser(Phaser parent, int numberOfParties)
- It creates a new phaser with the given parent and numberOfParties registered unarrived parties.
- Phaser(Phaser parent)
- This is equivalent to Phaser(parent, 0).
- int register()
- Register a new party to this phaser. It returns the phase number of the phase to which it is registered.
- int arrive()
- It is used to signal that a party has completed a phase. If the number of arrivals equals the number of registered parties, the phase is completed and the
Phasermoves on to the next phase.
- int arriveAndAwaitAdvance()
- It indicate the completion of a phase and then wait until all other registrants have also completed that phase. This method do not wait until the phase is complete. Returns the current phase number or a negative value if the phaser has been terminated.