102 |
|
t.join(); |
103 |
|
} |
104 |
|
|
105 |
– |
|
105 |
|
/** |
106 |
|
* An interruption in one party causes others waiting in await to |
107 |
|
* throw BrokenBarrierException |
256 |
|
public void testReset_Leakage() throws InterruptedException { |
257 |
|
final CyclicBarrier c = new CyclicBarrier(2); |
258 |
|
final AtomicBoolean done = new AtomicBoolean(); |
259 |
< |
Thread t = new Thread() { |
260 |
< |
public void run() { |
261 |
< |
while (!done.get()) { |
262 |
< |
try { |
263 |
< |
while (c.isBroken()) |
264 |
< |
c.reset(); |
265 |
< |
|
266 |
< |
c.await(); |
267 |
< |
threadFail("await should not return"); |
269 |
< |
} |
270 |
< |
catch (BrokenBarrierException e) { |
271 |
< |
} |
272 |
< |
catch (InterruptedException ie) { |
273 |
< |
} |
259 |
> |
Thread t = new Thread(new CheckedRunnable() { |
260 |
> |
public void realRun() { |
261 |
> |
while (!done.get()) { |
262 |
> |
try { |
263 |
> |
while (c.isBroken()) |
264 |
> |
c.reset(); |
265 |
> |
|
266 |
> |
c.await(); |
267 |
> |
shouldThrow(); |
268 |
|
} |
269 |
< |
} |
270 |
< |
}; |
269 |
> |
catch (BrokenBarrierException ok) {} |
270 |
> |
catch (InterruptedException ok) {} |
271 |
> |
}}}); |
272 |
|
|
273 |
|
t.start(); |
274 |
|
for (int i = 0; i < 4; i++) { |
275 |
< |
delay(SHORT_DELAY_MS); |
275 |
> |
delay(timeoutMillis()); |
276 |
|
t.interrupt(); |
277 |
|
} |
278 |
|
done.set(true); |
279 |
|
t.interrupt(); |
280 |
< |
t.join(); |
280 |
> |
awaitTermination(t); |
281 |
|
} |
282 |
|
|
283 |
|
/** |
377 |
|
} |
378 |
|
} |
379 |
|
|
385 |
– |
|
380 |
|
/** |
381 |
|
* Reset of a barrier after a failed command reinitializes it. |
382 |
|
*/ |