48 |
|
final Runnable task = new CheckedRunnable() { |
49 |
|
public void realRun() { done.countDown(); }}; |
50 |
|
p.execute(task); |
51 |
< |
assertTrue(done.await(SMALL_DELAY_MS, MILLISECONDS)); |
51 |
> |
assertTrue(done.await(LONG_DELAY_MS, MILLISECONDS)); |
52 |
|
} |
53 |
|
} |
54 |
|
|
156 |
|
public void realRun() { done.countDown(); }}; |
157 |
|
ScheduledFuture h = |
158 |
|
p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS); |
159 |
< |
done.await(); |
159 |
> |
await(done); |
160 |
|
h.cancel(true); |
161 |
|
double normalizedTime = |
162 |
|
(double) millisElapsedSince(startTime) / delay; |
182 |
|
public void realRun() { done.countDown(); }}; |
183 |
|
ScheduledFuture h = |
184 |
|
p.scheduleWithFixedDelay(task, 0, delay, MILLISECONDS); |
185 |
< |
done.await(); |
185 |
> |
await(done); |
186 |
|
h.cancel(true); |
187 |
|
double normalizedTime = |
188 |
|
(double) millisElapsedSince(startTime) / delay; |
315 |
|
public void realRun() throws InterruptedException { |
316 |
|
threadStarted.countDown(); |
317 |
|
assertEquals(1, p.getActiveCount()); |
318 |
< |
done.await(); |
318 |
> |
await(done); |
319 |
|
}}); |
320 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
320 |
> |
await(threadStarted); |
321 |
|
assertEquals(1, p.getActiveCount()); |
322 |
|
done.countDown(); |
323 |
|
} |
373 |
|
final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(THREADS); |
374 |
|
final CountDownLatch threadsStarted = new CountDownLatch(THREADS); |
375 |
|
final CountDownLatch done = new CountDownLatch(1); |
376 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
376 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
377 |
|
assertEquals(0, p.getLargestPoolSize()); |
378 |
|
for (int i = 0; i < THREADS; i++) |
379 |
|
p.execute(new CheckedRunnable() { |
380 |
|
public void realRun() throws InterruptedException { |
381 |
|
threadsStarted.countDown(); |
382 |
< |
done.await(); |
382 |
> |
await(done); |
383 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
384 |
|
}}); |
385 |
< |
assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
385 |
> |
await(threadsStarted); |
386 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
387 |
– |
done.countDown(); |
387 |
|
} |
388 |
|
assertEquals(THREADS, p.getLargestPoolSize()); |
389 |
|
} |
396 |
|
final ThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
397 |
|
final CountDownLatch threadStarted = new CountDownLatch(1); |
398 |
|
final CountDownLatch done = new CountDownLatch(1); |
399 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
399 |
> |
try (PoolCleaner cleaner = cleaner(p, done)) { |
400 |
|
assertEquals(0, p.getPoolSize()); |
401 |
|
p.execute(new CheckedRunnable() { |
402 |
|
public void realRun() throws InterruptedException { |
403 |
|
threadStarted.countDown(); |
404 |
|
assertEquals(1, p.getPoolSize()); |
405 |
< |
done.await(); |
405 |
> |
await(done); |
406 |
|
}}); |
407 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
407 |
> |
await(threadStarted); |
408 |
|
assertEquals(1, p.getPoolSize()); |
410 |
– |
done.countDown(); |
409 |
|
} |
410 |
|
} |
411 |
|
|
424 |
|
p.execute(new CheckedRunnable() { |
425 |
|
public void realRun() throws InterruptedException { |
426 |
|
threadStarted.countDown(); |
427 |
< |
done.await(); |
427 |
> |
await(done); |
428 |
|
}}); |
429 |
< |
assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); |
429 |
> |
await(threadStarted); |
430 |
|
assertEquals(1, p.getTaskCount()); |
431 |
|
assertEquals(0, p.getCompletedTaskCount()); |
432 |
|
for (int i = 0; i < TASKS; i++) { |
435 |
|
public void realRun() throws InterruptedException { |
436 |
|
threadStarted.countDown(); |
437 |
|
assertEquals(1 + TASKS, p.getTaskCount()); |
438 |
< |
done.await(); |
438 |
> |
await(done); |
439 |
|
}}); |
440 |
|
} |
441 |
|
assertEquals(1 + TASKS, p.getTaskCount()); |
510 |
|
public void realRun() throws InterruptedException { |
511 |
|
assertFalse(p.isTerminated()); |
512 |
|
threadStarted.countDown(); |
513 |
< |
done.await(); |
513 |
> |
await(done); |
514 |
|
}}); |
515 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
515 |
> |
await(threadStarted); |
516 |
|
assertFalse(p.isTerminating()); |
517 |
|
done.countDown(); |
518 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
534 |
|
public void realRun() throws InterruptedException { |
535 |
|
assertFalse(p.isTerminating()); |
536 |
|
threadStarted.countDown(); |
537 |
< |
done.await(); |
537 |
> |
await(done); |
538 |
|
}}); |
539 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
539 |
> |
await(threadStarted); |
540 |
|
assertFalse(p.isTerminating()); |
541 |
|
done.countDown(); |
542 |
|
try { p.shutdown(); } catch (SecurityException ok) { return; } |
559 |
|
Runnable r = new CheckedRunnable() { |
560 |
|
public void realRun() throws InterruptedException { |
561 |
|
threadStarted.countDown(); |
562 |
< |
done.await(); |
562 |
> |
await(done); |
563 |
|
}}; |
564 |
|
tasks[i] = p.schedule(r, 1, MILLISECONDS); |
565 |
|
} |
566 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
566 |
> |
await(threadStarted); |
567 |
|
BlockingQueue<Runnable> q = p.getQueue(); |
568 |
|
assertTrue(q.contains(tasks[tasks.length - 1])); |
569 |
|
assertFalse(q.contains(tasks[0])); |
584 |
|
Runnable r = new CheckedRunnable() { |
585 |
|
public void realRun() throws InterruptedException { |
586 |
|
threadStarted.countDown(); |
587 |
< |
done.await(); |
587 |
> |
await(done); |
588 |
|
}}; |
589 |
|
tasks[i] = p.schedule(r, 1, MILLISECONDS); |
590 |
|
} |
591 |
< |
assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); |
591 |
> |
await(threadStarted); |
592 |
|
BlockingQueue<Runnable> q = p.getQueue(); |
593 |
|
assertFalse(p.remove((Runnable)tasks[0])); |
594 |
|
assertTrue(q.contains((Runnable)tasks[4])); |
607 |
|
* purge eventually removes cancelled tasks from the queue |
608 |
|
*/ |
609 |
|
public void testPurge() throws InterruptedException { |
610 |
< |
ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
611 |
< |
ScheduledFuture[] tasks = new ScheduledFuture[5]; |
612 |
< |
for (int i = 0; i < tasks.length; i++) |
613 |
< |
tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), |
614 |
< |
LONG_DELAY_MS, MILLISECONDS); |
615 |
< |
try { |
610 |
> |
final ScheduledFuture[] tasks = new ScheduledFuture[5]; |
611 |
> |
final Runnable releaser = new Runnable() { public void run() { |
612 |
> |
for (ScheduledFuture task : tasks) |
613 |
> |
if (task != null) task.cancel(true); }}; |
614 |
> |
final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); |
615 |
> |
try (PoolCleaner cleaner = cleaner(p, releaser)) { |
616 |
> |
for (int i = 0; i < tasks.length; i++) |
617 |
> |
tasks[i] = p.schedule(new SmallPossiblyInterruptedRunnable(), |
618 |
> |
LONG_DELAY_MS, MILLISECONDS); |
619 |
|
int max = tasks.length; |
620 |
|
if (tasks[4].cancel(true)) --max; |
621 |
|
if (tasks[3].cancel(true)) --max; |
627 |
|
long count = p.getTaskCount(); |
628 |
|
if (count == max) |
629 |
|
return; |
630 |
< |
} while (millisElapsedSince(startTime) < MEDIUM_DELAY_MS); |
630 |
> |
} while (millisElapsedSince(startTime) < LONG_DELAY_MS); |
631 |
|
fail("Purge failed to remove cancelled tasks"); |
631 |
– |
} finally { |
632 |
– |
for (ScheduledFuture task : tasks) |
633 |
– |
task.cancel(true); |
634 |
– |
joinPool(p); |
632 |
|
} |
633 |
|
} |
634 |
|
|
652 |
|
}}; |
653 |
|
for (int i = 0; i < count; i++) |
654 |
|
p.execute(waiter); |
655 |
< |
assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS)); |
655 |
> |
await(threadsStarted); |
656 |
|
assertEquals(poolSize, p.getActiveCount()); |
657 |
|
assertEquals(0, p.getCompletedTaskCount()); |
658 |
|
final List<Runnable> queuedTasks; |
1139 |
|
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1140 |
|
l.add(new NPETask()); |
1141 |
|
List<Future<String>> futures = |
1142 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1142 |
> |
e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); |
1143 |
|
assertEquals(1, futures.size()); |
1144 |
|
try { |
1145 |
|
futures.get(0).get(); |