325 |
|
new CustomTPE(2, 2, |
326 |
|
LONG_DELAY_MS, MILLISECONDS, |
327 |
|
new ArrayBlockingQueue<Runnable>(10)); |
328 |
< |
final CountDownLatch threadStarted = new CountDownLatch(1); |
329 |
< |
final CountDownLatch threadProceed = new CountDownLatch(1); |
330 |
< |
final CountDownLatch threadDone = new CountDownLatch(1); |
331 |
< |
try { |
328 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
329 |
> |
final CountDownLatch threadStarted = new CountDownLatch(1); |
330 |
> |
final CountDownLatch threadProceed = new CountDownLatch(1); |
331 |
> |
final CountDownLatch threadDone = new CountDownLatch(1); |
332 |
|
assertEquals(0, p.getCompletedTaskCount()); |
333 |
|
p.execute(new CheckedRunnable() { |
334 |
|
public void realRun() throws InterruptedException { |
347 |
|
fail("timed out"); |
348 |
|
Thread.yield(); |
349 |
|
} |
350 |
– |
} finally { |
351 |
– |
joinPool(p); |
350 |
|
} |
351 |
|
} |
352 |
|
|
354 |
|
* getCorePoolSize returns size given in constructor if not otherwise set |
355 |
|
*/ |
356 |
|
public void testGetCorePoolSize() { |
357 |
< |
ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
358 |
< |
assertEquals(1, p.getCorePoolSize()); |
359 |
< |
joinPool(p); |
357 |
> |
ThreadPoolExecutor p = |
358 |
> |
new CustomTPE(1, 1, |
359 |
> |
LONG_DELAY_MS, MILLISECONDS, |
360 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
361 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
362 |
> |
assertEquals(1, p.getCorePoolSize()); |
363 |
> |
} |
364 |
|
} |
365 |
|
|
366 |
|
/** |
367 |
|
* getKeepAliveTime returns value given in constructor if not otherwise set |
368 |
|
*/ |
369 |
|
public void testGetKeepAliveTime() { |
370 |
< |
ThreadPoolExecutor p = new CustomTPE(2, 2, 1000, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
371 |
< |
assertEquals(1, p.getKeepAliveTime(SECONDS)); |
372 |
< |
joinPool(p); |
370 |
> |
ThreadPoolExecutor p = |
371 |
> |
new CustomTPE(2, 2, |
372 |
> |
1000, MILLISECONDS, |
373 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
374 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
375 |
> |
assertEquals(1, p.getKeepAliveTime(SECONDS)); |
376 |
> |
} |
377 |
|
} |
378 |
|
|
379 |
|
/** |
380 |
|
* getThreadFactory returns factory in constructor if not set |
381 |
|
*/ |
382 |
|
public void testGetThreadFactory() { |
383 |
< |
ThreadFactory tf = new SimpleThreadFactory(); |
384 |
< |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10), tf, new NoOpREHandler()); |
385 |
< |
assertSame(tf, p.getThreadFactory()); |
386 |
< |
joinPool(p); |
383 |
> |
ThreadFactory threadFactory = new SimpleThreadFactory(); |
384 |
> |
ThreadPoolExecutor p = |
385 |
> |
new CustomTPE(1, 2, |
386 |
> |
LONG_DELAY_MS, MILLISECONDS, |
387 |
> |
new ArrayBlockingQueue<Runnable>(10), |
388 |
> |
threadFactory, |
389 |
> |
new NoOpREHandler()); |
390 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
391 |
> |
assertSame(threadFactory, p.getThreadFactory()); |
392 |
> |
} |
393 |
|
} |
394 |
|
|
395 |
|
/** |
396 |
|
* setThreadFactory sets the thread factory returned by getThreadFactory |
397 |
|
*/ |
398 |
|
public void testSetThreadFactory() { |
399 |
< |
ThreadPoolExecutor p = new CustomTPE(1,2,LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
400 |
< |
ThreadFactory tf = new SimpleThreadFactory(); |
401 |
< |
p.setThreadFactory(tf); |
402 |
< |
assertSame(tf, p.getThreadFactory()); |
403 |
< |
joinPool(p); |
399 |
> |
ThreadPoolExecutor p = |
400 |
> |
new CustomTPE(1, 2, |
401 |
> |
LONG_DELAY_MS, MILLISECONDS, |
402 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
403 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
404 |
> |
ThreadFactory threadFactory = new SimpleThreadFactory(); |
405 |
> |
p.setThreadFactory(threadFactory); |
406 |
> |
assertSame(threadFactory, p.getThreadFactory()); |
407 |
> |
} |
408 |
|
} |
409 |
|
|
410 |
|
/** |