1070 |
|
* submit(runnable) throws RejectedExecutionException if saturated. |
1071 |
|
*/ |
1072 |
|
public void testSaturatedSubmitRunnable() { |
1073 |
< |
ThreadPoolExecutor p = |
1073 |
> |
final ThreadPoolExecutor p = |
1074 |
|
new ThreadPoolExecutor(1, 1, |
1075 |
|
LONG_DELAY_MS, MILLISECONDS, |
1076 |
|
new ArrayBlockingQueue<Runnable>(1)); |
1099 |
|
* submit(callable) throws RejectedExecutionException if saturated. |
1100 |
|
*/ |
1101 |
|
public void testSaturatedSubmitCallable() { |
1102 |
< |
ThreadPoolExecutor p = |
1102 |
> |
final ThreadPoolExecutor p = |
1103 |
|
new ThreadPoolExecutor(1, 1, |
1104 |
|
LONG_DELAY_MS, MILLISECONDS, |
1105 |
|
new ArrayBlockingQueue<Runnable>(1)); |
1214 |
|
* execute throws RejectedExecutionException if shutdown |
1215 |
|
*/ |
1216 |
|
public void testRejectedExecutionExceptionOnShutdown() { |
1217 |
< |
ThreadPoolExecutor p = |
1217 |
> |
final ThreadPoolExecutor p = |
1218 |
|
new ThreadPoolExecutor(1, 1, |
1219 |
|
LONG_DELAY_MS, MILLISECONDS, |
1220 |
|
new ArrayBlockingQueue<Runnable>(1)); |
1238 |
|
new ArrayBlockingQueue<Runnable>(1), h); |
1239 |
|
|
1240 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
1241 |
< |
try { |
1241 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
1242 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
1243 |
|
p.execute(r); |
1244 |
|
assertFalse(r.done); |
1245 |
– |
} finally { |
1246 |
– |
joinPool(p); |
1245 |
|
} |
1246 |
|
} |
1247 |
|
|
1249 |
|
* execute using DiscardPolicy drops task on shutdown |
1250 |
|
*/ |
1251 |
|
public void testDiscardOnShutdown() { |
1252 |
< |
RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy(); |
1255 |
< |
ThreadPoolExecutor p = |
1252 |
> |
final ThreadPoolExecutor p = |
1253 |
|
new ThreadPoolExecutor(1, 1, |
1254 |
|
LONG_DELAY_MS, MILLISECONDS, |
1255 |
|
new ArrayBlockingQueue<Runnable>(1), |
1256 |
< |
h); |
1256 |
> |
new ThreadPoolExecutor.DiscardPolicy()); |
1257 |
|
|
1258 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
1259 |
< |
try { |
1259 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
1260 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
1261 |
|
p.execute(r); |
1262 |
|
assertFalse(r.done); |
1266 |
– |
} finally { |
1267 |
– |
joinPool(p); |
1263 |
|
} |
1264 |
|
} |
1265 |
|
|
1267 |
|
* execute using DiscardOldestPolicy drops task on shutdown |
1268 |
|
*/ |
1269 |
|
public void testDiscardOldestOnShutdown() { |
1270 |
< |
RejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy(); |
1276 |
< |
ThreadPoolExecutor p = |
1270 |
> |
final ThreadPoolExecutor p = |
1271 |
|
new ThreadPoolExecutor(1, 1, |
1272 |
|
LONG_DELAY_MS, MILLISECONDS, |
1273 |
|
new ArrayBlockingQueue<Runnable>(1), |
1274 |
< |
h); |
1274 |
> |
new ThreadPoolExecutor.DiscardOldestPolicy()); |
1275 |
|
|
1276 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
1277 |
< |
try { |
1277 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
1278 |
|
TrackedNoOpRunnable r = new TrackedNoOpRunnable(); |
1279 |
|
p.execute(r); |
1280 |
|
assertFalse(r.done); |
1287 |
– |
} finally { |
1288 |
– |
joinPool(p); |
1281 |
|
} |
1282 |
|
} |
1283 |
|
|
1285 |
|
* execute(null) throws NPE |
1286 |
|
*/ |
1287 |
|
public void testExecuteNull() { |
1288 |
< |
ThreadPoolExecutor p = |
1289 |
< |
new ThreadPoolExecutor(1, 2, 1L, SECONDS, |
1288 |
> |
final ThreadPoolExecutor p = |
1289 |
> |
new ThreadPoolExecutor(1, 2, |
1290 |
> |
1L, SECONDS, |
1291 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1292 |
< |
try { |
1293 |
< |
p.execute(null); |
1294 |
< |
shouldThrow(); |
1295 |
< |
} catch (NullPointerException success) {} |
1296 |
< |
|
1297 |
< |
joinPool(p); |
1292 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
1293 |
> |
try { |
1294 |
> |
p.execute(null); |
1295 |
> |
shouldThrow(); |
1296 |
> |
} catch (NullPointerException success) {} |
1297 |
> |
} |
1298 |
|
} |
1299 |
|
|
1300 |
|
/** |
1301 |
|
* setCorePoolSize of negative value throws IllegalArgumentException |
1302 |
|
*/ |
1303 |
|
public void testCorePoolSizeIllegalArgumentException() { |
1304 |
< |
ThreadPoolExecutor p = |
1304 |
> |
final ThreadPoolExecutor p = |
1305 |
|
new ThreadPoolExecutor(1, 2, |
1306 |
|
LONG_DELAY_MS, MILLISECONDS, |
1307 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1308 |
< |
try { |
1309 |
< |
p.setCorePoolSize(-1); |
1310 |
< |
shouldThrow(); |
1311 |
< |
} catch (IllegalArgumentException success) { |
1312 |
< |
} finally { |
1320 |
< |
try { p.shutdown(); } catch (SecurityException ok) { return; } |
1308 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
1309 |
> |
try { |
1310 |
> |
p.setCorePoolSize(-1); |
1311 |
> |
shouldThrow(); |
1312 |
> |
} catch (IllegalArgumentException success) {} |
1313 |
|
} |
1322 |
– |
joinPool(p); |
1314 |
|
} |
1315 |
|
|
1316 |
|
/** |
1318 |
|
* given a value less the core pool size |
1319 |
|
*/ |
1320 |
|
public void testMaximumPoolSizeIllegalArgumentException() { |
1321 |
< |
ThreadPoolExecutor p = |
1321 |
> |
final ThreadPoolExecutor p = |
1322 |
|
new ThreadPoolExecutor(2, 3, |
1323 |
|
LONG_DELAY_MS, MILLISECONDS, |
1324 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1337 |
|
* if given a negative value |
1338 |
|
*/ |
1339 |
|
public void testMaximumPoolSizeIllegalArgumentException2() { |
1340 |
< |
ThreadPoolExecutor p = |
1340 |
> |
final ThreadPoolExecutor p = |
1341 |
|
new ThreadPoolExecutor(2, 3, |
1342 |
|
LONG_DELAY_MS, MILLISECONDS, |
1343 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1356 |
|
* max pool size result in IllegalArgumentException. |
1357 |
|
*/ |
1358 |
|
public void testPoolSizeInvariants() { |
1359 |
< |
ThreadPoolExecutor p = |
1359 |
> |
final ThreadPoolExecutor p = |
1360 |
|
new ThreadPoolExecutor(1, 1, |
1361 |
|
LONG_DELAY_MS, MILLISECONDS, |
1362 |
|
new ArrayBlockingQueue<Runnable>(10)); |
1384 |
|
* when given a negative value |
1385 |
|
*/ |
1386 |
|
public void testKeepAliveTimeIllegalArgumentException() { |
1387 |
< |
ThreadPoolExecutor p = |
1387 |
> |
final ThreadPoolExecutor p = |
1388 |
|
new ThreadPoolExecutor(2, 3, |
1389 |
|
LONG_DELAY_MS, MILLISECONDS, |
1390 |
|
new ArrayBlockingQueue<Runnable>(10)); |