1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
import junit.framework.*; |
535 |
|
try { |
536 |
|
p.execute(new CheckedRunnable() { |
537 |
|
public void realRun() throws InterruptedException { |
538 |
– |
threadStarted.countDown(); |
538 |
|
assertFalse(p.isTerminated()); |
539 |
+ |
threadStarted.countDown(); |
540 |
|
done.await(); |
541 |
|
}}); |
542 |
|
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
543 |
+ |
assertFalse(p.isTerminating()); |
544 |
|
done.countDown(); |
545 |
|
} finally { |
546 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
560 |
|
assertFalse(p.isTerminating()); |
561 |
|
p.execute(new CheckedRunnable() { |
562 |
|
public void realRun() throws InterruptedException { |
562 |
– |
threadStarted.countDown(); |
563 |
|
assertFalse(p.isTerminating()); |
564 |
+ |
threadStarted.countDown(); |
565 |
|
done.await(); |
566 |
|
}}); |
567 |
|
assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); |
722 |
|
public void testShutDown2() throws InterruptedException { |
723 |
|
CustomExecutor p = new CustomExecutor(1); |
724 |
|
p.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); |
725 |
+ |
assertFalse(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
726 |
+ |
assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
727 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
728 |
|
for (int i = 0; i < tasks.length; i++) |
729 |
|
tasks[i] = p.schedule(new NoOpRunnable(), |
748 |
|
*/ |
749 |
|
public void testShutDown3() throws InterruptedException { |
750 |
|
CustomExecutor p = new CustomExecutor(1); |
751 |
+ |
assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
752 |
+ |
assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
753 |
|
p.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); |
754 |
+ |
assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
755 |
+ |
assertFalse(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
756 |
|
ScheduledFuture task = |
757 |
|
p.scheduleAtFixedRate(new NoOpRunnable(), 5, 5, MILLISECONDS); |
758 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
771 |
|
*/ |
772 |
|
public void testShutDown4() throws InterruptedException { |
773 |
|
CustomExecutor p = new CustomExecutor(1); |
767 |
– |
p.setContinueExistingPeriodicTasksAfterShutdownPolicy(true); |
774 |
|
final CountDownLatch counter = new CountDownLatch(2); |
775 |
|
try { |
776 |
+ |
p.setContinueExistingPeriodicTasksAfterShutdownPolicy(true); |
777 |
+ |
assertTrue(p.getExecuteExistingDelayedTasksAfterShutdownPolicy()); |
778 |
+ |
assertTrue(p.getContinueExistingPeriodicTasksAfterShutdownPolicy()); |
779 |
|
final Runnable r = new CheckedRunnable() { |
780 |
|
public void realRun() { |
781 |
|
counter.countDown(); |