CyclicBarrier in Java
1. Description
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.
The threads wait for each other by calling the await() method on the CyclicBarrier. Once N threads are waiting at the CyclicBarrier, all threads are released and can continue running
2. API
int |
await() Waits until all parties have invoked await on this barrier. |
int |
await(long timeout, TimeUnit unit) Waits until all parties have invoked await on this barrier. |
int |
getNumberWaiting() Returns the number of parties currently waiting at the barrier. |
int |
getParties() Returns the number of parties required to trip this barrier. |
boolean |
isBroken() Queries if this barrier is in a broken state. |
void |
reset() Resets the barrier to its initial state. |
3. Sample











































































posted on 2011-05-07 15:35 XXXXXX 閱讀(648) 評(píng)論(0) 編輯 收藏 所屬分類: Programing