662 |
|
* purge removes cancelled tasks from the queue |
663 |
|
*/ |
664 |
|
public void testPurge() throws InterruptedException { |
665 |
+ |
final ScheduledFuture[] tasks = new ScheduledFuture[5]; |
666 |
+ |
final Runnable releaser = new Runnable() { public void run() { |
667 |
+ |
for (ScheduledFuture task : tasks) |
668 |
+ |
if (task != null) task.cancel(true); }}; |
669 |
|
final CustomExecutor p = new CustomExecutor(1); |
670 |
< |
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
671 |
< |
for (int i = 0; i < tasks.length; i++) |
672 |
< |
tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), |
673 |
< |
LONG_DELAY_MS, MILLISECONDS); |
670 |
< |
try { |
670 |
> |
try (PoolCleaner cleaner = cleaner(p, releaser)) { |
671 |
> |
for (int i = 0; i < tasks.length; i++) |
672 |
> |
tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), |
673 |
> |
LONG_DELAY_MS, MILLISECONDS); |
674 |
|
int max = tasks.length; |
675 |
|
if (tasks[4].cancel(true)) --max; |
676 |
|
if (tasks[3].cancel(true)) --max; |
682 |
|
long count = p.getTaskCount(); |
683 |
|
if (count == max) |
684 |
|
return; |
685 |
< |
} while (millisElapsedSince(startTime) < MEDIUM_DELAY_MS); |
685 |
> |
} while (millisElapsedSince(startTime) < LONG_DELAY_MS); |
686 |
|
fail("Purge failed to remove cancelled tasks"); |
684 |
– |
} finally { |
685 |
– |
for (ScheduledFuture task : tasks) |
686 |
– |
task.cancel(true); |
687 |
– |
joinPool(p); |
687 |
|
} |
688 |
|
} |
689 |
|
|