349 |
|
assertSame(q, wq); |
350 |
|
assertFalse(wq.contains(tasks[0])); |
351 |
|
assertTrue(wq.contains(tasks[4])); |
352 |
+ |
for (int i = 1; i < 5; ++i) |
353 |
+ |
tasks[i].cancel(true); |
354 |
+ |
p1.shutdownNow(); |
355 |
|
} catch(Exception e) { |
356 |
|
unexpectedException(); |
357 |
|
} finally { |
1528 |
|
joinPool(e); |
1529 |
|
} |
1530 |
|
} |
1531 |
+ |
|
1532 |
+ |
/** |
1533 |
+ |
* allowsCoreThreadTimeOut is by default false. |
1534 |
+ |
*/ |
1535 |
+ |
public void testAllowsCoreThreadTimeOut() { |
1536 |
+ |
ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 2, 1000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1537 |
+ |
assertFalse(tpe.allowsCoreThreadTimeOut()); |
1538 |
+ |
joinPool(tpe); |
1539 |
+ |
} |
1540 |
+ |
|
1541 |
+ |
/** |
1542 |
+ |
* allowCoreThreadTimeOut(true) causes idle threads to time out |
1543 |
+ |
*/ |
1544 |
+ |
public void testAllowCoreThreadTimeOut_true() { |
1545 |
+ |
ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1546 |
+ |
tpe.allowCoreThreadTimeOut(true); |
1547 |
+ |
tpe.execute(new NoOpRunnable()); |
1548 |
+ |
try { |
1549 |
+ |
Thread.sleep(MEDIUM_DELAY_MS); |
1550 |
+ |
assertEquals(0, tpe.getPoolSize()); |
1551 |
+ |
} catch(InterruptedException e){ |
1552 |
+ |
unexpectedException(); |
1553 |
+ |
} finally { |
1554 |
+ |
joinPool(tpe); |
1555 |
+ |
} |
1556 |
+ |
} |
1557 |
+ |
|
1558 |
+ |
/** |
1559 |
+ |
* allowCoreThreadTimeOut(false) causes idle threads not to time out |
1560 |
+ |
*/ |
1561 |
+ |
public void testAllowCoreThreadTimeOut_false() { |
1562 |
+ |
ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
1563 |
+ |
tpe.allowCoreThreadTimeOut(false); |
1564 |
+ |
tpe.execute(new NoOpRunnable()); |
1565 |
+ |
try { |
1566 |
+ |
Thread.sleep(MEDIUM_DELAY_MS); |
1567 |
+ |
assertTrue(tpe.getPoolSize() >= 1); |
1568 |
+ |
} catch(InterruptedException e){ |
1569 |
+ |
unexpectedException(); |
1570 |
+ |
} finally { |
1571 |
+ |
joinPool(tpe); |
1572 |
+ |
} |
1573 |
+ |
} |
1574 |
+ |
|
1575 |
|
} |