1462 |
|
} |
1463 |
|
|
1464 |
|
/** |
1465 |
< |
* invokeAll(collection) throws exception if any task does |
1465 |
> |
* invokeAll(collection) throws exception if any task does |
1466 |
|
*/ |
1467 |
|
public void testAbnormalInvokeAllCollectionCC() { |
1468 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1484 |
|
checkInvoke(a); |
1485 |
|
} |
1486 |
|
|
1487 |
– |
|
1487 |
|
/** |
1488 |
|
* awaitQuiescent by a worker is equivalent in effect to |
1489 |
|
* ForkJoinTask.helpQuiesce() |
1490 |
< |
*/ |
1490 |
> |
*/ |
1491 |
|
public void testAwaitQuiescent1() throws Exception { |
1492 |
|
final ForkJoinPool p = new ForkJoinPool(); |
1493 |
|
try { |
1494 |
|
final long startTime = System.nanoTime(); |
1495 |
|
assertTrue(p.isQuiescent()); |
1496 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1497 |
< |
protected void realCompute() { |
1498 |
< |
FibAction f = new FibAction(8); |
1499 |
< |
assertSame(f, f.fork()); |
1500 |
< |
boolean t = ForkJoinTask.getPool().awaitQuiescence(MEDIUM_DELAY_MS, TimeUnit.SECONDS); |
1501 |
< |
assertTrue(t); |
1502 |
< |
while (!f.isDone()) { |
1503 |
< |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1504 |
< |
threadFail("timed out"); |
1505 |
< |
assertFalse(p.getAsyncMode()); |
1506 |
< |
assertFalse(p.isShutdown()); |
1507 |
< |
assertFalse(p.isTerminating()); |
1508 |
< |
assertFalse(p.isTerminated()); |
1509 |
< |
Thread.yield(); |
1510 |
< |
} |
1511 |
< |
assertFalse(p.isQuiescent()); |
1512 |
< |
assertEquals(0, ForkJoinTask.getQueuedTaskCount()); |
1513 |
< |
try { |
1514 |
< |
assertEquals(21, f.result); |
1515 |
< |
} catch (Throwable fail) { |
1516 |
< |
threadFail(fail.getMessage()); |
1518 |
< |
} |
1497 |
> |
protected void realCompute() { |
1498 |
> |
FibAction f = new FibAction(8); |
1499 |
> |
assertSame(f, f.fork()); |
1500 |
> |
boolean t = ForkJoinTask.getPool().awaitQuiescence(MEDIUM_DELAY_MS, TimeUnit.SECONDS); |
1501 |
> |
assertTrue(t); |
1502 |
> |
while (!f.isDone()) { |
1503 |
> |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1504 |
> |
threadFail("timed out"); |
1505 |
> |
assertFalse(p.getAsyncMode()); |
1506 |
> |
assertFalse(p.isShutdown()); |
1507 |
> |
assertFalse(p.isTerminating()); |
1508 |
> |
assertFalse(p.isTerminated()); |
1509 |
> |
Thread.yield(); |
1510 |
> |
} |
1511 |
> |
assertFalse(p.isQuiescent()); |
1512 |
> |
assertEquals(0, ForkJoinTask.getQueuedTaskCount()); |
1513 |
> |
try { |
1514 |
> |
assertEquals(21, f.result); |
1515 |
> |
} catch (Throwable fail) { |
1516 |
> |
threadFail(fail.getMessage()); |
1517 |
|
} |
1518 |
< |
}; |
1518 |
> |
}}; |
1519 |
|
p.execute(a); |
1520 |
|
while (!a.isDone() || !p.isQuiescent()) { |
1521 |
|
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1539 |
|
joinPool(p); |
1540 |
|
} |
1541 |
|
} |
1542 |
< |
|
1542 |
> |
|
1543 |
|
/** |
1544 |
|
* awaitQuiescent returns when pool isQuiescent() or the indicated |
1545 |
|
* timeout elapse |
1546 |
< |
*/ |
1546 |
> |
*/ |
1547 |
|
public void testAwaitQuiescent2() throws Exception { |
1548 |
|
final ForkJoinPool p = new ForkJoinPool(); |
1549 |
|
try { |
1552 |
– |
final long startTime = System.nanoTime(); |
1550 |
|
assertTrue(p.isQuiescent()); |
1551 |
< |
ForkJoinTask a = new CheckedRecursiveAction() { |
1551 |
> |
for (;;) { |
1552 |
> |
final long startTime = System.nanoTime(); |
1553 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1554 |
|
protected void realCompute() { |
1555 |
|
FibAction f = new FibAction(8); |
1556 |
|
assertSame(f, f.fork()); |
1568 |
|
try { |
1569 |
|
assertEquals(21, f.result); |
1570 |
|
} catch (Throwable fail) { System.out.println("fail " + fail.getMessage()); } |
1571 |
< |
} |
1572 |
< |
}; |
1573 |
< |
p.execute(a); |
1574 |
< |
while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) { |
1575 |
< |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1576 |
< |
threadFail("timed out"); |
1571 |
> |
}}; |
1572 |
> |
p.execute(a); |
1573 |
> |
if (a.isDone() || p.isQuiescent()) |
1574 |
> |
continue; // Already done so cannot test; retry |
1575 |
> |
while (!p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)) { |
1576 |
> |
if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1577 |
> |
threadFail("timed out"); |
1578 |
> |
assertFalse(p.getAsyncMode()); |
1579 |
> |
assertFalse(p.isShutdown()); |
1580 |
> |
assertFalse(p.isTerminating()); |
1581 |
> |
assertFalse(p.isTerminated()); |
1582 |
> |
Thread.yield(); |
1583 |
> |
} |
1584 |
> |
assertTrue(p.isQuiescent()); |
1585 |
> |
assertTrue(a.isDone()); |
1586 |
> |
assertEquals(0, p.getQueuedTaskCount()); |
1587 |
|
assertFalse(p.getAsyncMode()); |
1588 |
+ |
assertEquals(0, p.getActiveThreadCount()); |
1589 |
+ |
assertEquals(0, p.getQueuedTaskCount()); |
1590 |
+ |
assertEquals(0, p.getQueuedSubmissionCount()); |
1591 |
+ |
assertFalse(p.hasQueuedSubmissions()); |
1592 |
|
assertFalse(p.isShutdown()); |
1593 |
|
assertFalse(p.isTerminating()); |
1594 |
|
assertFalse(p.isTerminated()); |
1595 |
< |
Thread.yield(); |
1595 |
> |
break; |
1596 |
|
} |
1584 |
– |
assertTrue(p.isQuiescent()); |
1585 |
– |
assertTrue(a.isDone()); |
1586 |
– |
assertEquals(0, p.getQueuedTaskCount()); |
1587 |
– |
assertFalse(p.getAsyncMode()); |
1588 |
– |
assertEquals(0, p.getActiveThreadCount()); |
1589 |
– |
assertEquals(0, p.getQueuedTaskCount()); |
1590 |
– |
assertEquals(0, p.getQueuedSubmissionCount()); |
1591 |
– |
assertFalse(p.hasQueuedSubmissions()); |
1592 |
– |
assertFalse(p.isShutdown()); |
1593 |
– |
assertFalse(p.isTerminating()); |
1594 |
– |
assertFalse(p.isTerminated()); |
1597 |
|
} finally { |
1598 |
|
joinPool(p); |
1599 |
|
} |
1600 |
|
} |
1601 |
|
|
1600 |
– |
|
1602 |
|
} |