Java Reference
In-Depth Information
CyclicBarrier
allows a fixed number of parties to rendezvous repeatedly at a
barrier
point
and is useful in parallel iterative algorithms that break down a problem into a fixed
number of independent subproblems. Threads call
await
when they reach the barrier point,
and
await
blocks until
all
the threads have reached the barrier point. If all threads meet at
the barrier point, the barrier has been successfully passed, in which case all threads are re-
leased and the barrier is reset so it can be used again. If a call to
await
times out or a thread
blocked in
await
is interrupted, then the barrier is considered
broken
and all outstanding
calls to
await
terminate with
BrokenBarrierException
. If the barrier is successfully
passed,
await
returns a unique arrival index for each thread, which can be used to “elect” a
leader that takes some special action in the next iteration.
CyclicBar rier
also lets you
pass a
barrier action
to the constructor; this is a
Runnable
that is executed (in one of the
subtask threads) when the barrier is successfully passed but before the blocked threads are
released.