Waits until all parties have been invoked on this barrier.
If the current thread is not the last to arrive, then it is disabled for thread-scheduling purposes and lies dormant until one of the following conditions are realized:
- The Last party arrives
- Some other thread interrupts the current thread
- Some other Thread interrupts one of the other waiting parties
- Some other party times out while waiting for the barrier
- This barrier is intolerant of party failures, and some other party prematurely leaves the barrier due to an external system event such as a network failure
- Some other party invokes {@link #reset()} on this barrier
If the current thread:
- has its interrupted status set on entry to this method; or
- is interrupted while waiting
Then the Barrier is broken for all other parties, and an {@link InterruptedException}is thrown on this thread, clearing the current interrupted status.
This Barrier is considered broken if one of the following conditions apply:
- Another party times out while waiting for the barrier
- Another party invoked {@link #reset()} on this barrier
- Another party prematurely leaves the barrier due to an external system event such as a network failure, and this barrier is set to be intolerant of party failures
- Another party received notification of a Thread Interruption
If any of these situations occur, a {@link java.util.concurrent.BrokenBarrierException} is thrown.
@return the index of this thread with respect to all other parties in the Barrier. If this thread is thefirst to arrive, index is {@link #getParties()}-1; the last thread to arrive will return 0
@throws InterruptedException if the local thread is interrupted, or if there is a communication errorwith ZooKeeper
@throws BrokenBarrierException if another party breaks the barrier, or another party calls reset whilewaiting for the Barrier to complete