329 |
|
*/ |
330 |
|
public void testGetLargestPoolSize() throws InterruptedException { |
331 |
|
final int THREADS = 3; |
332 |
+ |
final CountDownLatch done = new CountDownLatch(1); |
333 |
|
final ThreadPoolExecutor p = |
334 |
|
new ThreadPoolExecutor(THREADS, THREADS, |
335 |
|
LONG_DELAY_MS, MILLISECONDS, |
336 |
|
new ArrayBlockingQueue<Runnable>(10)); |
337 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
337 |
< |
final CountDownLatch threadsStarted = new CountDownLatch(THREADS); |
338 |
< |
final CountDownLatch done = new CountDownLatch(1); |
337 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
338 |
|
assertEquals(0, p.getLargestPoolSize()); |
339 |
+ |
final CountDownLatch threadsStarted = new CountDownLatch(THREADS); |
340 |
|
for (int i = 0; i < THREADS; i++) |
341 |
|
p.execute(new CheckedRunnable() { |
342 |
|
public void realRun() throws InterruptedException { |
346 |
|
}}); |
347 |
|
assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS)); |
348 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
349 |
– |
done.countDown(); // release pool |
349 |
|
} |
350 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
351 |
|
} |
373 |
|
* become active |
374 |
|
*/ |
375 |
|
public void testGetPoolSize() throws InterruptedException { |
376 |
+ |
final CountDownLatch done = new CountDownLatch(1); |
377 |
|
final ThreadPoolExecutor p = |
378 |
|
new ThreadPoolExecutor(1, 1, |
379 |
|
LONG_DELAY_MS, MILLISECONDS, |
380 |
|
new ArrayBlockingQueue<Runnable>(10)); |
381 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
382 |
< |
final CountDownLatch threadStarted = new CountDownLatch(1); |
383 |
< |
final CountDownLatch done = new CountDownLatch(1); |
381 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
382 |
|
assertEquals(0, p.getPoolSize()); |
383 |
+ |
final CountDownLatch threadStarted = new CountDownLatch(1); |
384 |
|
p.execute(new CheckedRunnable() { |
385 |
|
public void realRun() throws InterruptedException { |
386 |
|
threadStarted.countDown(); |
389 |
|
}}); |
390 |
|
assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); |
391 |
|
assertEquals(1, p.getPoolSize()); |
393 |
– |
done.countDown(); // release pool |
392 |
|
} |
393 |
|
} |
394 |
|
|