119 |
|
assertEquals(1, p.getActiveCount()); |
120 |
|
done.await(); |
121 |
|
}}); |
122 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
122 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
123 |
|
assertEquals(1, p.getActiveCount()); |
124 |
|
} finally { |
125 |
|
done.countDown(); |
321 |
|
new ThreadPoolExecutor(1, 2, |
322 |
|
LONG_DELAY_MS, MILLISECONDS, |
323 |
|
new ArrayBlockingQueue<Runnable>(10)); |
324 |
< |
try { |
325 |
< |
p.setRejectedExecutionHandler(null); |
326 |
< |
shouldThrow(); |
327 |
< |
} catch (NullPointerException success) { |
328 |
< |
} finally { |
329 |
< |
joinPool(p); |
324 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
325 |
> |
try { |
326 |
> |
p.setRejectedExecutionHandler(null); |
327 |
> |
shouldThrow(); |
328 |
> |
} catch (NullPointerException success) {} |
329 |
|
} |
330 |
|
} |
331 |
|
|
339 |
|
new ThreadPoolExecutor(THREADS, THREADS, |
340 |
|
LONG_DELAY_MS, MILLISECONDS, |
341 |
|
new ArrayBlockingQueue<Runnable>(10)); |
342 |
< |
final CountDownLatch threadsStarted = new CountDownLatch(THREADS); |
343 |
< |
final CountDownLatch done = new CountDownLatch(1); |
344 |
< |
try { |
342 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
343 |
> |
final CountDownLatch threadsStarted = new CountDownLatch(THREADS); |
344 |
> |
final CountDownLatch done = new CountDownLatch(1); |
345 |
|
assertEquals(0, p.getLargestPoolSize()); |
346 |
|
for (int i = 0; i < THREADS; i++) |
347 |
|
p.execute(new CheckedRunnable() { |
350 |
|
done.await(); |
351 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
352 |
|
}}); |
353 |
< |
assertTrue(threadsStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
355 |
< |
assertEquals(THREADS, p.getLargestPoolSize()); |
356 |
< |
} finally { |
357 |
< |
done.countDown(); |
358 |
< |
joinPool(p); |
353 |
> |
assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
354 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
355 |
+ |
done.countDown(); // release pool |
356 |
|
} |
357 |
+ |
assertEquals(THREADS, p.getLargestPoolSize()); |
358 |
|
} |
359 |
|
|
360 |
|
/** |
366 |
|
new ThreadPoolExecutor(2, 3, |
367 |
|
LONG_DELAY_MS, MILLISECONDS, |
368 |
|
new ArrayBlockingQueue<Runnable>(10)); |
369 |
< |
assertEquals(3, p.getMaximumPoolSize()); |
370 |
< |
joinPool(p); |
369 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
370 |
> |
assertEquals(3, p.getMaximumPoolSize()); |
371 |
> |
p.setMaximumPoolSize(5); |
372 |
> |
assertEquals(5, p.getMaximumPoolSize()); |
373 |
> |
p.setMaximumPoolSize(4); |
374 |
> |
assertEquals(4, p.getMaximumPoolSize()); |
375 |
> |
} |
376 |
|
} |
377 |
|
|
378 |
|
/** |
384 |
|
new ThreadPoolExecutor(1, 1, |
385 |
|
LONG_DELAY_MS, MILLISECONDS, |
386 |
|
new ArrayBlockingQueue<Runnable>(10)); |
387 |
< |
final CountDownLatch threadStarted = new CountDownLatch(1); |
388 |
< |
final CountDownLatch done = new CountDownLatch(1); |
389 |
< |
try { |
387 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
388 |
> |
final CountDownLatch threadStarted = new CountDownLatch(1); |
389 |
> |
final CountDownLatch done = new CountDownLatch(1); |
390 |
|
assertEquals(0, p.getPoolSize()); |
391 |
|
p.execute(new CheckedRunnable() { |
392 |
|
public void realRun() throws InterruptedException { |
394 |
|
assertEquals(1, p.getPoolSize()); |
395 |
|
done.await(); |
396 |
|
}}); |
397 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
397 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
398 |
|
assertEquals(1, p.getPoolSize()); |
399 |
< |
} finally { |
398 |
< |
done.countDown(); |
399 |
< |
joinPool(p); |
399 |
> |
done.countDown(); // release pool |
400 |
|
} |
401 |
|
} |
402 |
|
|
418 |
|
assertEquals(1, p.getTaskCount()); |
419 |
|
done.await(); |
420 |
|
}}); |
421 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
421 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
422 |
|
assertEquals(1, p.getTaskCount()); |
423 |
|
} finally { |
424 |
|
done.countDown(); |
488 |
|
threadStarted.countDown(); |
489 |
|
done.await(); |
490 |
|
}}); |
491 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
491 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
492 |
|
assertFalse(p.isTerminating()); |
493 |
|
done.countDown(); |
494 |
|
} finally { |
516 |
|
threadStarted.countDown(); |
517 |
|
done.await(); |
518 |
|
}}); |
519 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
519 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
520 |
|
assertFalse(p.isTerminating()); |
521 |
|
done.countDown(); |
522 |
|
} finally { |
551 |
|
tasks[i] = new FutureTask(task); |
552 |
|
p.execute(tasks[i]); |
553 |
|
} |
554 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
554 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
555 |
|
assertSame(q, p.getQueue()); |
556 |
|
assertFalse(q.contains(tasks[0])); |
557 |
|
assertTrue(q.contains(tasks[tasks.length - 1])); |
583 |
|
}}; |
584 |
|
p.execute(tasks[i]); |
585 |
|
} |
586 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
586 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
587 |
|
assertFalse(p.remove(tasks[0])); |
588 |
|
assertTrue(q.contains(tasks[4])); |
589 |
|
assertTrue(q.contains(tasks[3])); |
622 |
|
tasks[i] = new FutureTask(task); |
623 |
|
p.execute(tasks[i]); |
624 |
|
} |
625 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
625 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
626 |
|
assertEquals(tasks.length, p.getTaskCount()); |
627 |
|
assertEquals(tasks.length - 1, q.size()); |
628 |
|
assertEquals(1L, p.getActiveCount()); |
1044 |
|
p.submit(task).get(); |
1045 |
|
}}); |
1046 |
|
|
1047 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
1047 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
1048 |
|
t.interrupt(); |
1049 |
|
awaitTermination(t, MEDIUM_DELAY_MS); |
1050 |
|
} finally { |