46 |
|
} |
47 |
|
} |
48 |
|
|
49 |
– |
|
49 |
|
/** |
50 |
|
* execute successfully executes a runnable |
51 |
|
*/ |
184 |
|
joinPool(p); |
185 |
|
} |
186 |
|
|
188 |
– |
|
187 |
|
/** |
188 |
|
* getThreadFactory returns factory in constructor if not set |
189 |
|
*/ |
213 |
|
joinPool(p); |
214 |
|
} |
215 |
|
|
218 |
– |
|
216 |
|
/** |
217 |
|
* setThreadFactory(null) throws NPE |
218 |
|
*/ |
259 |
|
joinPool(p); |
260 |
|
} |
261 |
|
|
265 |
– |
|
262 |
|
/** |
263 |
|
* setRejectedExecutionHandler(null) throws NPE |
264 |
|
*/ |
276 |
|
} |
277 |
|
} |
278 |
|
|
283 |
– |
|
279 |
|
/** |
280 |
|
* getLargestPoolSize increases, but doesn't overestimate, when |
281 |
|
* multiple threads active |
386 |
|
joinPool(p); |
387 |
|
} |
388 |
|
|
394 |
– |
|
389 |
|
/** |
390 |
|
* isTerminated is false before termination, true after |
391 |
|
*/ |
581 |
|
|
582 |
|
// Exception Tests |
583 |
|
|
590 |
– |
|
584 |
|
/** |
585 |
|
* Constructor throws if corePoolSize argument is less than zero |
586 |
|
*/ |
653 |
|
} catch (NullPointerException success) {} |
654 |
|
} |
655 |
|
|
663 |
– |
|
664 |
– |
|
656 |
|
/** |
657 |
|
* Constructor throws if corePoolSize argument is less than zero |
658 |
|
*/ |
744 |
|
} catch (NullPointerException success) {} |
745 |
|
} |
746 |
|
|
756 |
– |
|
747 |
|
/** |
748 |
|
* Constructor throws if corePoolSize argument is less than zero |
749 |
|
*/ |
835 |
|
} catch (NullPointerException success) {} |
836 |
|
} |
837 |
|
|
848 |
– |
|
838 |
|
/** |
839 |
|
* Constructor throws if corePoolSize argument is less than zero |
840 |
|
*/ |
1201 |
|
} |
1202 |
|
} |
1203 |
|
|
1215 |
– |
|
1204 |
|
/** |
1205 |
|
* execute using DiscardOldestPolicy drops task on shutdown |
1206 |
|
*/ |
1222 |
|
} |
1223 |
|
} |
1224 |
|
|
1237 |
– |
|
1225 |
|
/** |
1226 |
|
* execute(null) throws NPE |
1227 |
|
*/ |
1294 |
|
joinPool(p); |
1295 |
|
} |
1296 |
|
|
1310 |
– |
|
1297 |
|
/** |
1298 |
|
* setKeepAliveTime throws IllegalArgumentException |
1299 |
|
* when given a negative value |
1392 |
|
} |
1393 |
|
} |
1394 |
|
|
1409 |
– |
|
1395 |
|
/** |
1396 |
|
* invokeAny(null) throws NPE |
1397 |
|
*/ |
1585 |
|
} |
1586 |
|
} |
1587 |
|
|
1603 |
– |
|
1604 |
– |
|
1588 |
|
/** |
1589 |
|
* timed invokeAny(null) throws NPE |
1590 |
|
*/ |
1886 |
|
* allowCoreThreadTimeOut(true) causes idle threads to time out |
1887 |
|
*/ |
1888 |
|
public void testAllowCoreThreadTimeOut_true() throws Exception { |
1889 |
+ |
long coreThreadTimeOut = SHORT_DELAY_MS; |
1890 |
|
final ThreadPoolExecutor p = |
1891 |
|
new ThreadPoolExecutor(2, 10, |
1892 |
< |
SHORT_DELAY_MS, MILLISECONDS, |
1892 |
> |
coreThreadTimeOut, MILLISECONDS, |
1893 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1894 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
1895 |
|
try { |
1896 |
|
p.allowCoreThreadTimeOut(true); |
1897 |
|
p.execute(new CheckedRunnable() { |
1898 |
< |
public void realRun() throws InterruptedException { |
1898 |
> |
public void realRun() { |
1899 |
|
threadStarted.countDown(); |
1900 |
|
assertEquals(1, p.getPoolSize()); |
1901 |
|
}}); |
1902 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
1903 |
< |
for (int i = 0; i < (MEDIUM_DELAY_MS/10); i++) { |
1904 |
< |
if (p.getPoolSize() == 0) |
1905 |
< |
break; |
1906 |
< |
delay(10); |
1907 |
< |
} |
1902 |
> |
await(threadStarted); |
1903 |
> |
delay(coreThreadTimeOut); |
1904 |
> |
long startTime = System.nanoTime(); |
1905 |
> |
while (p.getPoolSize() > 0 |
1906 |
> |
&& millisElapsedSince(startTime) < LONG_DELAY_MS) |
1907 |
> |
Thread.yield(); |
1908 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1909 |
|
assertEquals(0, p.getPoolSize()); |
1910 |
|
} finally { |
1911 |
|
joinPool(p); |
1916 |
|
* allowCoreThreadTimeOut(false) causes idle threads not to time out |
1917 |
|
*/ |
1918 |
|
public void testAllowCoreThreadTimeOut_false() throws Exception { |
1919 |
+ |
long coreThreadTimeOut = SHORT_DELAY_MS; |
1920 |
|
final ThreadPoolExecutor p = |
1921 |
|
new ThreadPoolExecutor(2, 10, |
1922 |
< |
SHORT_DELAY_MS, MILLISECONDS, |
1922 |
> |
coreThreadTimeOut, MILLISECONDS, |
1923 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1924 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
1925 |
|
try { |
1929 |
|
threadStarted.countDown(); |
1930 |
|
assertTrue(p.getPoolSize() >= 1); |
1931 |
|
}}); |
1932 |
< |
delay(SMALL_DELAY_MS); |
1932 |
> |
delay(2 * coreThreadTimeOut); |
1933 |
|
assertTrue(p.getPoolSize() >= 1); |
1934 |
|
} finally { |
1935 |
|
joinPool(p); |