497 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
498 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
499 |
|
for(int i = 0; i < 5; i++){ |
500 |
< |
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); |
500 |
> |
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
501 |
|
} |
502 |
|
try { |
503 |
|
Thread.sleep(SHORT_DELAY_MS); |
525 |
|
ScheduledThreadPoolExecutor p1 = new ScheduledThreadPoolExecutor(1); |
526 |
|
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
527 |
|
for(int i = 0; i < 5; i++){ |
528 |
< |
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), 1, TimeUnit.MILLISECONDS); |
528 |
> |
tasks[i] = p1.schedule(new SmallPossiblyInterruptedRunnable(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
529 |
> |
} |
530 |
> |
try { |
531 |
> |
int max = 5; |
532 |
> |
if (tasks[4].cancel(true)) --max; |
533 |
> |
if (tasks[3].cancel(true)) --max; |
534 |
> |
// There must eventually be an interference-free point at |
535 |
> |
// which purge will not fail. (At worst, when queue is empty.) |
536 |
> |
int k; |
537 |
> |
for (k = 0; k < SMALL_DELAY_MS; ++k) { |
538 |
> |
p1.purge(); |
539 |
> |
long count = p1.getTaskCount(); |
540 |
> |
if (count >= 0 && count <= max) |
541 |
> |
break; |
542 |
> |
Thread.sleep(1); |
543 |
> |
} |
544 |
> |
assertTrue(k < SMALL_DELAY_MS); |
545 |
> |
} catch(Exception e) { |
546 |
> |
unexpectedException(); |
547 |
> |
} finally { |
548 |
> |
joinPool(p1); |
549 |
|
} |
530 |
– |
int max = 5; |
531 |
– |
if (tasks[4].cancel(true)) --max; |
532 |
– |
if (tasks[3].cancel(true)) --max; |
533 |
– |
p1.purge(); |
534 |
– |
long count = p1.getTaskCount(); |
535 |
– |
assertTrue(count > 0 && count <= max); |
536 |
– |
joinPool(p1); |
550 |
|
} |
551 |
|
|
552 |
|
/** |