115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
– |
|
118 |
|
static class CustomTPE extends ThreadPoolExecutor { |
119 |
|
protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) { |
120 |
|
return new CustomTask<V>(c); |
187 |
|
} |
188 |
|
} |
189 |
|
|
191 |
– |
|
190 |
|
/** |
191 |
|
* execute successfully executes a runnable |
192 |
|
*/ |
313 |
|
joinPool(p); |
314 |
|
} |
315 |
|
|
318 |
– |
|
316 |
|
/** |
317 |
|
* getThreadFactory returns factory in constructor if not set |
318 |
|
*/ |
334 |
|
joinPool(p); |
335 |
|
} |
336 |
|
|
340 |
– |
|
337 |
|
/** |
338 |
|
* setThreadFactory(null) throws NPE |
339 |
|
*/ |
370 |
|
joinPool(p); |
371 |
|
} |
372 |
|
|
377 |
– |
|
373 |
|
/** |
374 |
|
* setRejectedExecutionHandler(null) throws NPE |
375 |
|
*/ |
384 |
|
} |
385 |
|
} |
386 |
|
|
392 |
– |
|
387 |
|
/** |
388 |
|
* getLargestPoolSize increases, but doesn't overestimate, when |
389 |
|
* multiple threads active |
489 |
|
joinPool(p); |
490 |
|
} |
491 |
|
|
498 |
– |
|
492 |
|
/** |
493 |
|
* isTerminated is false before termination, true after |
494 |
|
*/ |
682 |
|
|
683 |
|
// Exception Tests |
684 |
|
|
692 |
– |
|
685 |
|
/** |
686 |
|
* Constructor throws if corePoolSize argument is less than zero |
687 |
|
*/ |
742 |
|
} catch (NullPointerException success) {} |
743 |
|
} |
744 |
|
|
753 |
– |
|
754 |
– |
|
745 |
|
/** |
746 |
|
* Constructor throws if corePoolSize argument is less than zero |
747 |
|
*/ |
813 |
|
} catch (NullPointerException success) {} |
814 |
|
} |
815 |
|
|
826 |
– |
|
816 |
|
/** |
817 |
|
* Constructor throws if corePoolSize argument is less than zero |
818 |
|
*/ |
884 |
|
} catch (NullPointerException success) {} |
885 |
|
} |
886 |
|
|
898 |
– |
|
887 |
|
/** |
888 |
|
* Constructor throws if corePoolSize argument is less than zero |
889 |
|
*/ |
969 |
|
} catch (NullPointerException success) {} |
970 |
|
} |
971 |
|
|
984 |
– |
|
972 |
|
/** |
973 |
|
* execute throws RejectedExecutionException if saturated. |
974 |
|
*/ |
1118 |
|
} |
1119 |
|
} |
1120 |
|
|
1134 |
– |
|
1121 |
|
/** |
1122 |
|
* execute using DiscardOldestPolicy drops task on shutdown |
1123 |
|
*/ |
1135 |
|
} |
1136 |
|
} |
1137 |
|
|
1152 |
– |
|
1138 |
|
/** |
1139 |
|
* execute(null) throws NPE |
1140 |
|
*/ |
1199 |
|
joinPool(p); |
1200 |
|
} |
1201 |
|
|
1217 |
– |
|
1202 |
|
/** |
1203 |
|
* setKeepAliveTime throws IllegalArgumentException |
1204 |
|
* when given a negative value |
1287 |
|
} |
1288 |
|
} |
1289 |
|
|
1306 |
– |
|
1290 |
|
/** |
1291 |
|
* invokeAny(null) throws NPE |
1292 |
|
*/ |
1448 |
|
} |
1449 |
|
} |
1450 |
|
|
1468 |
– |
|
1469 |
– |
|
1451 |
|
/** |
1452 |
|
* timed invokeAny(null) throws NPE |
1453 |
|
*/ |
1707 |
|
* allowCoreThreadTimeOut(true) causes idle threads to time out |
1708 |
|
*/ |
1709 |
|
public void testAllowCoreThreadTimeOut_true() throws Exception { |
1710 |
+ |
long coreThreadTimeOut = SHORT_DELAY_MS; |
1711 |
|
final ThreadPoolExecutor p = |
1712 |
|
new CustomTPE(2, 10, |
1713 |
< |
SHORT_DELAY_MS, MILLISECONDS, |
1713 |
> |
coreThreadTimeOut, MILLISECONDS, |
1714 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1715 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
1716 |
|
try { |
1720 |
|
threadStarted.countDown(); |
1721 |
|
assertEquals(1, p.getPoolSize()); |
1722 |
|
}}); |
1723 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
1724 |
< |
for (int i = 0; i < (MEDIUM_DELAY_MS/10); i++) { |
1725 |
< |
if (p.getPoolSize() == 0) |
1726 |
< |
break; |
1727 |
< |
delay(10); |
1728 |
< |
} |
1723 |
> |
await(threadStarted); |
1724 |
> |
delay(coreThreadTimeOut); |
1725 |
> |
long startTime = System.nanoTime(); |
1726 |
> |
while (p.getPoolSize() > 0 |
1727 |
> |
&& millisElapsedSince(startTime) < LONG_DELAY_MS) |
1728 |
> |
Thread.yield(); |
1729 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1730 |
|
assertEquals(0, p.getPoolSize()); |
1731 |
|
} finally { |
1732 |
|
joinPool(p); |
1737 |
|
* allowCoreThreadTimeOut(false) causes idle threads not to time out |
1738 |
|
*/ |
1739 |
|
public void testAllowCoreThreadTimeOut_false() throws Exception { |
1740 |
+ |
long coreThreadTimeOut = SHORT_DELAY_MS; |
1741 |
|
final ThreadPoolExecutor p = |
1742 |
|
new CustomTPE(2, 10, |
1743 |
< |
SHORT_DELAY_MS, MILLISECONDS, |
1743 |
> |
coreThreadTimeOut, MILLISECONDS, |
1744 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1745 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
1746 |
|
try { |
1750 |
|
threadStarted.countDown(); |
1751 |
|
assertTrue(p.getPoolSize() >= 1); |
1752 |
|
}}); |
1753 |
< |
delay(SMALL_DELAY_MS); |
1753 |
> |
delay(2 * coreThreadTimeOut); |
1754 |
|
assertTrue(p.getPoolSize() >= 1); |
1755 |
|
} finally { |
1756 |
|
joinPool(p); |