CyclicBarrier
A
synchronization aid that allows a set of threads to all wait for each
other to reach a common barrier point. CyclicBarriers are useful in
programs involving a fixed sized party of threads that must
occasionally wait for each other.
The
barrier is called cyclic
because it can be re-used after the waiting threads are released.
A
CyclicBarrier supports an optional Runnable command that is run once
per barrier point, after the last thread in the party arrives, but
before any threads are released. This barrier
action is
useful for updating shared-state before any of the parties continue.
Example:
So,
a Cyclic-Barrier (CB) is different from Count-Down-Latch (CDL) in 2
ways:
It
has a barrier-action thread to run when all threads reach waiting
state.
It
can be reused after all threads have reached waiting state once.
|