85 |
|
* point prematurely because of interruption, failure, or timeout, all |
86 |
|
* other threads waiting at that barrier point will also leave |
87 |
|
* abnormally via {@link BrokenBarrierException} (or |
88 |
< |
* <tt>InterruptedException</tt> if they too were interrupted at about |
88 |
> |
* {@link InterruptedException} if they too were interrupted at about |
89 |
|
* the same time). |
90 |
|
* |
91 |
|
* @since 1.5 |
123 |
|
|
124 |
|
/** |
125 |
|
* Number of parties still waiting. Counts down from parties to 0 |
126 |
< |
* on each generation. This only has meaning for the current non-broken |
127 |
< |
* generation. It is reset to parties on each new generation. |
126 |
> |
* on each generation. It is reset to parties on each new |
127 |
> |
* generation or when broken. |
128 |
|
*/ |
129 |
|
private int count; |
130 |
|
|
147 |
|
*/ |
148 |
|
private void breakBarrier() { |
149 |
|
generation.broken = true; |
150 |
+ |
count = parties; |
151 |
|
trip.signalAll(); |
152 |
|
} |
153 |
|
|
174 |
|
if (index == 0) { // tripped |
175 |
|
boolean ranAction = false; |
176 |
|
try { |
177 |
< |
if (barrierCommand != null) |
178 |
< |
barrierCommand.run(); |
177 |
> |
final Runnable command = barrierCommand; |
178 |
> |
if (command != null) |
179 |
> |
command.run(); |
180 |
|
ranAction = true; |
181 |
|
nextGeneration(); |
182 |
|
return 0; |
237 |
|
/** |
238 |
|
* Creates a new <tt>CyclicBarrier</tt> that will trip when the |
239 |
|
* given number of parties (threads) are waiting upon it, and |
240 |
< |
* does not perform a predefined action upon each barrier. |
240 |
> |
* does not perform a predefined action when the barrier is tripped. |
241 |
|
* |
242 |
|
* @param parties the number of threads that must invoke {@link #await} |
243 |
|
* before the barrier is tripped. |
251 |
|
/** |
252 |
|
* Returns the number of parties required to trip this barrier. |
253 |
|
* @return the number of parties required to trip this barrier. |
254 |
< |
**/ |
254 |
> |
*/ |
255 |
|
public int getParties() { |
256 |
|
return parties; |
257 |
|
} |
434 |
|
final ReentrantLock lock = this.lock; |
435 |
|
lock.lock(); |
436 |
|
try { |
437 |
< |
return generation.broken ? 0 : parties - count; |
437 |
> |
return parties - count; |
438 |
|
} finally { |
439 |
|
lock.unlock(); |
440 |
|
} |