Waits until all {@link #getParties parties} have invoked
awaiton 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 following things happens:
- The last thread arrives; or
- Some other thread {@link Thread#interrupt interrupts} the currentthread; or
- Some other thread {@link Thread#interrupt interrupts} one of theother waiting threads; or
- Some other thread times out while waiting for barrier; or
- Some other thread invokes {@link #reset} on this barrier.
If the current thread:
- has its interrupted status set on entry to this method; or
- is {@link Thread#interrupt interrupted} while waiting
then {@link InterruptedException} is thrown and the current thread'sinterrupted status is cleared.
If the barrier is {@link #reset} while any thread is waiting, or ifthe barrier {@link #isBroken is broken} when await is invoked,or while any thread is waiting, then {@link BrokenBarrierException} is thrown.
If any thread is {@link Thread#interrupt interrupted} while waiting,then all other waiting threads will throw {@link BrokenBarrierException} and the barrier is placed in the brokenstate.
If the current thread is the last thread to arrive, and a non-null barrier action was supplied in the constructor, then the current thread runs the action before allowing the other threads to continue. If an exception occurs during the barrier action then that exception will be propagated in the current thread and the barrier is placed in the broken state.
@return the arrival index of the current thread, where index {@link #getParties()} - 1 indicates the first to arrive andzero indicates the last to arrive.
@throws InterruptedException if the current thread was interruptedwhile waiting.
@throws BrokenBarrierException if another thread wasinterrupted or timed out while the current thread was waiting, or the barrier was reset, or the barrier was broken when await was called, or the barrier action (if present) failed due an exception.