465 |
|
*/ |
466 |
|
public void testArriveAndAwaitAdvance3() throws InterruptedException { |
467 |
|
final Phaser phaser = new Phaser(1); |
468 |
– |
final AtomicInteger arrivingCount = new AtomicInteger(0); |
468 |
|
final List<Thread> threads = new ArrayList<Thread>(); |
469 |
< |
for (int i = 0; i < 6; i++) { |
469 |
> |
for (int i = 0; i < 3; i++) { |
470 |
|
threads.add(newStartedThread(new CheckedRunnable() { |
471 |
< |
public void realRun() throws InterruptedException { |
472 |
< |
phaser.register(); |
473 |
< |
sleepTillInterrupted(SHORT_DELAY_MS); |
474 |
< |
arrivingCount.getAndIncrement(); |
476 |
< |
phaser.arrive(); |
477 |
< |
}})); |
471 |
> |
public void realRun() throws InterruptedException { |
472 |
> |
phaser.register(); |
473 |
> |
phaser.arriveAndAwaitAdvance(); |
474 |
> |
}})); |
475 |
|
} |
476 |
< |
int phaseNumber = phaser.arriveAndAwaitAdvance(); |
477 |
< |
arrivingCount.incrementAndGet(); |
478 |
< |
//the + 1 adds to expectedArrive to account for the main threads arrival |
482 |
< |
int expectedArrived = phaseNumber > 0 ? phaseNumber * six + 1 : phaser.getArrivedParties() + 1; |
483 |
< |
assertEquals(expectedArrived, arrivingCount.get()); |
476 |
> |
Thread.sleep(LONG_DELAY_MS); |
477 |
> |
assertEquals(phaser.getArrivedParties(), 3); |
478 |
> |
phaser.arriveAndAwaitAdvance(); |
479 |
|
for (Thread thread : threads) |
480 |
|
thread.join(); |
481 |
|
} |