569 |
|
* isShutdown is false before shutdown, true after |
570 |
|
*/ |
571 |
|
public void testIsShutdown() { |
572 |
< |
|
573 |
< |
ThreadPoolExecutor p = new CustomTPE(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue<Runnable>(10)); |
574 |
< |
assertFalse(p.isShutdown()); |
575 |
< |
try { p.shutdown(); } catch (SecurityException ok) { return; } |
576 |
< |
assertTrue(p.isShutdown()); |
577 |
< |
joinPool(p); |
572 |
> |
final ThreadPoolExecutor p = |
573 |
> |
new CustomTPE(1, 1, |
574 |
> |
LONG_DELAY_MS, MILLISECONDS, |
575 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
576 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
577 |
> |
assertFalse(p.isShutdown()); |
578 |
> |
try { p.shutdown(); } catch (SecurityException ok) { return; } |
579 |
> |
assertTrue(p.isShutdown()); |
580 |
> |
} |
581 |
|
} |
582 |
|
|
583 |
|
/** |
588 |
|
new CustomTPE(1, 1, |
589 |
|
LONG_DELAY_MS, MILLISECONDS, |
590 |
|
new ArrayBlockingQueue<Runnable>(10)); |
591 |
< |
final CountDownLatch threadStarted = new CountDownLatch(1); |
592 |
< |
final CountDownLatch done = new CountDownLatch(1); |
593 |
< |
try { |
591 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
592 |
> |
final CountDownLatch threadStarted = new CountDownLatch(1); |
593 |
> |
final CountDownLatch done = new CountDownLatch(1); |
594 |
|
assertFalse(p.isTerminating()); |
595 |
|
p.execute(new CheckedRunnable() { |
596 |
|
public void realRun() throws InterruptedException { |
601 |
|
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
602 |
|
assertFalse(p.isTerminating()); |
603 |
|
done.countDown(); |
601 |
– |
} finally { |
604 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
605 |
+ |
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
606 |
+ |
assertTrue(p.isTerminated()); |
607 |
+ |
assertFalse(p.isTerminating()); |
608 |
|
} |
604 |
– |
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
605 |
– |
assertTrue(p.isTerminated()); |
606 |
– |
assertFalse(p.isTerminating()); |
609 |
|
} |
610 |
|
|
611 |
|
/** |
616 |
|
new CustomTPE(1, 1, |
617 |
|
LONG_DELAY_MS, MILLISECONDS, |
618 |
|
new ArrayBlockingQueue<Runnable>(10)); |
619 |
< |
final CountDownLatch threadStarted = new CountDownLatch(1); |
620 |
< |
final CountDownLatch done = new CountDownLatch(1); |
621 |
< |
try { |
619 |
> |
try (PoolCleaner cleaner = cleaner(p)) { |
620 |
> |
final CountDownLatch threadStarted = new CountDownLatch(1); |
621 |
> |
final CountDownLatch done = new CountDownLatch(1); |
622 |
|
assertFalse(p.isTerminating()); |
623 |
|
p.execute(new CheckedRunnable() { |
624 |
|
public void realRun() throws InterruptedException { |
629 |
|
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
630 |
|
assertFalse(p.isTerminating()); |
631 |
|
done.countDown(); |
630 |
– |
} finally { |
632 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
633 |
+ |
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
634 |
+ |
assertTrue(p.isTerminated()); |
635 |
+ |
assertFalse(p.isTerminating()); |
636 |
|
} |
633 |
– |
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS)); |
634 |
– |
assertTrue(p.isTerminated()); |
635 |
– |
assertFalse(p.isTerminating()); |
637 |
|
} |
638 |
|
|
639 |
|
/** |