ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ScheduledExecutorTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ScheduledExecutorTest.java (file contents):
Revision 1.65 by jsr166, Mon Oct 5 21:42:48 2015 UTC vs.
Revision 1.66 by jsr166, Mon Oct 5 21:54:33 2015 UTC

# Line 609 | Line 609 | public class ScheduledExecutorTest exten
609       * purge eventually removes cancelled tasks from the queue
610       */
611      public void testPurge() throws InterruptedException {
612 <        ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
613 <        ScheduledFuture[] tasks = new ScheduledFuture[5];
614 <        for (int i = 0; i < tasks.length; i++)
615 <            tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(),
616 <                                  LONG_DELAY_MS, MILLISECONDS);
617 <        try {
612 >        final ScheduledFuture[] tasks = new ScheduledFuture[5];
613 >        final Runnable releaser = new Runnable() { public void run() {
614 >            for (ScheduledFuture task : tasks)
615 >                if (task != null) task.cancel(true); }};
616 >        final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
617 >        try (PoolCleaner cleaner = cleaner(p, releaser)) {
618 >            for (int i = 0; i < tasks.length; i++)
619 >                tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(),
620 >                                      LONG_DELAY_MS, MILLISECONDS);
621              int max = tasks.length;
622              if (tasks[4].cancel(true)) --max;
623              if (tasks[3].cancel(true)) --max;
# Line 626 | Line 629 | public class ScheduledExecutorTest exten
629                  long count = p.getTaskCount();
630                  if (count == max)
631                      return;
632 <            } while (millisElapsedSince(startTime) < MEDIUM_DELAY_MS);
632 >            } while (millisElapsedSince(startTime) < LONG_DELAY_MS);
633              fail("Purge failed to remove cancelled tasks");
631        } finally {
632            for (ScheduledFuture task : tasks)
633                task.cancel(true);
634            joinPool(p);
634          }
635      }
636  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines