87 |
|
new ThreadPoolExecutor(1, 1, |
88 |
|
LONG_DELAY_MS, MILLISECONDS, |
89 |
|
new ArrayBlockingQueue<Runnable>(10)); |
90 |
< |
final CountDownLatch done = new CountDownLatch(1); |
91 |
< |
final Runnable task = new CheckedRunnable() { |
92 |
< |
public void realRun() { |
93 |
< |
done.countDown(); |
94 |
< |
}}; |
95 |
< |
try { |
90 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
91 |
> |
final CountDownLatch done = new CountDownLatch(1); |
92 |
> |
final Runnable task = new CheckedRunnable() { |
93 |
> |
public void realRun() { done.countDown(); }}; |
94 |
|
p.execute(task); |
95 |
< |
assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS)); |
98 |
< |
} finally { |
99 |
< |
joinPool(p); |
95 |
> |
assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); |
96 |
|
} |
97 |
|
} |
98 |
|
|
105 |
|
new ThreadPoolExecutor(2, 2, |
106 |
|
LONG_DELAY_MS, MILLISECONDS, |
107 |
|
new ArrayBlockingQueue<Runnable>(10)); |
108 |
< |
final CountDownLatch threadStarted = new CountDownLatch(1); |
109 |
< |
final CountDownLatch done = new CountDownLatch(1); |
110 |
< |
try { |
108 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
109 |
> |
final CountDownLatch threadStarted = new CountDownLatch(1); |
110 |
> |
final CountDownLatch done = new CountDownLatch(1); |
111 |
|
assertEquals(0, p.getActiveCount()); |
112 |
|
p.execute(new CheckedRunnable() { |
113 |
|
public void realRun() throws InterruptedException { |
115 |
|
assertEquals(1, p.getActiveCount()); |
116 |
|
done.await(); |
117 |
|
}}); |
118 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
118 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
119 |
|
assertEquals(1, p.getActiveCount()); |
124 |
– |
} finally { |
120 |
|
done.countDown(); |
126 |
– |
joinPool(p); |
121 |
|
} |
122 |
|
} |
123 |
|
|
378 |
|
new ThreadPoolExecutor(1, 1, |
379 |
|
LONG_DELAY_MS, MILLISECONDS, |
380 |
|
new ArrayBlockingQueue<Runnable>(10)); |
381 |
< |
final CountDownLatch threadStarted = new CountDownLatch(1); |
382 |
< |
final CountDownLatch done = new CountDownLatch(1); |
383 |
< |
try { |
381 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
382 |
> |
final CountDownLatch threadStarted = new CountDownLatch(1); |
383 |
> |
final CountDownLatch done = new CountDownLatch(1); |
384 |
|
assertEquals(0, p.getPoolSize()); |
385 |
|
p.execute(new CheckedRunnable() { |
386 |
|
public void realRun() throws InterruptedException { |
388 |
|
assertEquals(1, p.getPoolSize()); |
389 |
|
done.await(); |
390 |
|
}}); |
391 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
391 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
392 |
|
assertEquals(1, p.getPoolSize()); |
393 |
< |
} finally { |
400 |
< |
done.countDown(); |
401 |
< |
joinPool(p); |
393 |
> |
done.countDown(); // release pool |
394 |
|
} |
395 |
|
} |
396 |
|
|
402 |
|
new ThreadPoolExecutor(1, 1, |
403 |
|
LONG_DELAY_MS, MILLISECONDS, |
404 |
|
new ArrayBlockingQueue<Runnable>(10)); |
405 |
< |
final CountDownLatch threadStarted = new CountDownLatch(1); |
406 |
< |
final CountDownLatch done = new CountDownLatch(1); |
407 |
< |
try { |
405 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
406 |
> |
final CountDownLatch threadStarted = new CountDownLatch(1); |
407 |
> |
final CountDownLatch done = new CountDownLatch(1); |
408 |
|
assertEquals(0, p.getTaskCount()); |
409 |
|
p.execute(new CheckedRunnable() { |
410 |
|
public void realRun() throws InterruptedException { |
412 |
|
assertEquals(1, p.getTaskCount()); |
413 |
|
done.await(); |
414 |
|
}}); |
415 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
415 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
416 |
|
assertEquals(1, p.getTaskCount()); |
425 |
– |
} finally { |
417 |
|
done.countDown(); |
427 |
– |
joinPool(p); |
418 |
|
} |
419 |
|
} |
420 |
|
|
480 |
|
threadStarted.countDown(); |
481 |
|
done.await(); |
482 |
|
}}); |
483 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
483 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
484 |
|
assertFalse(p.isTerminating()); |
485 |
|
done.countDown(); |
486 |
|
} finally { |
508 |
|
threadStarted.countDown(); |
509 |
|
done.await(); |
510 |
|
}}); |
511 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
511 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
512 |
|
assertFalse(p.isTerminating()); |
513 |
|
done.countDown(); |
514 |
|
} finally { |
543 |
|
tasks[i] = new FutureTask(task); |
544 |
|
p.execute(tasks[i]); |
545 |
|
} |
546 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
546 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
547 |
|
assertSame(q, p.getQueue()); |
548 |
|
assertFalse(q.contains(tasks[0])); |
549 |
|
assertTrue(q.contains(tasks[tasks.length - 1])); |
575 |
|
}}; |
576 |
|
p.execute(tasks[i]); |
577 |
|
} |
578 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
578 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
579 |
|
assertFalse(p.remove(tasks[0])); |
580 |
|
assertTrue(q.contains(tasks[4])); |
581 |
|
assertTrue(q.contains(tasks[3])); |
614 |
|
tasks[i] = new FutureTask(task); |
615 |
|
p.execute(tasks[i]); |
616 |
|
} |
617 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
617 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
618 |
|
assertEquals(tasks.length, p.getTaskCount()); |
619 |
|
assertEquals(tasks.length - 1, q.size()); |
620 |
|
assertEquals(1L, p.getActiveCount()); |
1036 |
|
p.submit(task).get(); |
1037 |
|
}}); |
1038 |
|
|
1039 |
< |
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
1039 |
> |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
1040 |
|
t.interrupt(); |
1041 |
|
awaitTermination(t, MEDIUM_DELAY_MS); |
1042 |
|
} finally { |