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 |
+ |
/** |
1488 |
+ |
* awaitQuiescence by a worker is equivalent in effect to |
1489 |
+ |
* ForkJoinTask.helpQuiesce() |
1490 |
+ |
*/ |
1491 |
+ |
public void testAwaitQuiescence1() 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 |
+ |
assertSame(p, ForkJoinTask.getPool()); |
1501 |
+ |
boolean quiescent = p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS); |
1502 |
+ |
assertTrue(quiescent); |
1503 |
+ |
assertFalse(p.isQuiescent()); |
1504 |
+ |
while (!f.isDone()) { |
1505 |
+ |
assertFalse(p.getAsyncMode()); |
1506 |
+ |
assertFalse(p.isShutdown()); |
1507 |
+ |
assertFalse(p.isTerminating()); |
1508 |
+ |
assertFalse(p.isTerminated()); |
1509 |
+ |
Thread.yield(); |
1510 |
+ |
} |
1511 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1512 |
+ |
assertFalse(p.isQuiescent()); |
1513 |
+ |
assertEquals(0, ForkJoinTask.getQueuedTaskCount()); |
1514 |
+ |
assertEquals(21, f.result); |
1515 |
+ |
}}; |
1516 |
+ |
p.execute(a); |
1517 |
+ |
while (!a.isDone() || !p.isQuiescent()) { |
1518 |
+ |
assertFalse(p.getAsyncMode()); |
1519 |
+ |
assertFalse(p.isShutdown()); |
1520 |
+ |
assertFalse(p.isTerminating()); |
1521 |
+ |
assertFalse(p.isTerminated()); |
1522 |
+ |
Thread.yield(); |
1523 |
+ |
} |
1524 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1525 |
+ |
assertEquals(0, p.getQueuedTaskCount()); |
1526 |
+ |
assertFalse(p.getAsyncMode()); |
1527 |
+ |
assertEquals(0, p.getActiveThreadCount()); |
1528 |
+ |
assertEquals(0, p.getQueuedTaskCount()); |
1529 |
+ |
assertEquals(0, p.getQueuedSubmissionCount()); |
1530 |
+ |
assertFalse(p.hasQueuedSubmissions()); |
1531 |
+ |
assertFalse(p.isShutdown()); |
1532 |
+ |
assertFalse(p.isTerminating()); |
1533 |
+ |
assertFalse(p.isTerminated()); |
1534 |
+ |
} finally { |
1535 |
+ |
joinPool(p); |
1536 |
+ |
} |
1537 |
+ |
} |
1538 |
+ |
|
1539 |
+ |
/** |
1540 |
+ |
* awaitQuiescence returns when pool isQuiescent() or the indicated |
1541 |
+ |
* timeout elapsed |
1542 |
+ |
*/ |
1543 |
+ |
public void testAwaitQuiescence2() throws Exception { |
1544 |
+ |
/** |
1545 |
+ |
* """It is possible to disable or limit the use of threads in the |
1546 |
+ |
* common pool by setting the parallelism property to zero. However |
1547 |
+ |
* doing so may cause unjoined tasks to never be executed.""" |
1548 |
+ |
*/ |
1549 |
+ |
if ("0".equals(System.getProperty( |
1550 |
+ |
"java.util.concurrent.ForkJoinPool.common.parallelism"))) |
1551 |
+ |
return; |
1552 |
+ |
final ForkJoinPool p = new ForkJoinPool(); |
1553 |
+ |
try { |
1554 |
+ |
assertTrue(p.isQuiescent()); |
1555 |
+ |
final long startTime = System.nanoTime(); |
1556 |
+ |
ForkJoinTask a = new CheckedRecursiveAction() { |
1557 |
+ |
protected void realCompute() { |
1558 |
+ |
FibAction f = new FibAction(8); |
1559 |
+ |
assertSame(f, f.fork()); |
1560 |
+ |
while (!f.isDone() |
1561 |
+ |
&& millisElapsedSince(startTime) < LONG_DELAY_MS) { |
1562 |
+ |
assertFalse(p.getAsyncMode()); |
1563 |
+ |
assertFalse(p.isShutdown()); |
1564 |
+ |
assertFalse(p.isTerminating()); |
1565 |
+ |
assertFalse(p.isTerminated()); |
1566 |
+ |
Thread.yield(); |
1567 |
+ |
} |
1568 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1569 |
+ |
assertEquals(0, ForkJoinTask.getQueuedTaskCount()); |
1570 |
+ |
assertEquals(21, f.result); |
1571 |
+ |
}}; |
1572 |
+ |
p.execute(a); |
1573 |
+ |
assertTrue(p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)); |
1574 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1575 |
+ |
assertTrue(p.isQuiescent()); |
1576 |
+ |
assertTrue(a.isDone()); |
1577 |
+ |
assertEquals(0, p.getQueuedTaskCount()); |
1578 |
+ |
assertFalse(p.getAsyncMode()); |
1579 |
+ |
assertEquals(0, p.getActiveThreadCount()); |
1580 |
+ |
assertEquals(0, p.getQueuedTaskCount()); |
1581 |
+ |
assertEquals(0, p.getQueuedSubmissionCount()); |
1582 |
+ |
assertFalse(p.hasQueuedSubmissions()); |
1583 |
+ |
assertFalse(p.isShutdown()); |
1584 |
+ |
assertFalse(p.isTerminating()); |
1585 |
+ |
assertFalse(p.isTerminated()); |
1586 |
+ |
} finally { |
1587 |
+ |
joinPool(p); |
1588 |
+ |
} |
1589 |
+ |
} |
1590 |
+ |
|
1591 |
|
} |