279 |
|
Executors.newScheduledThreadPool(2), |
280 |
|
}; |
281 |
|
|
282 |
+ |
final CountDownLatch done = new CountDownLatch(1); |
283 |
+ |
|
284 |
|
final Runnable sleeper = new CheckedRunnable() { |
285 |
|
public void realRun() throws InterruptedException { |
286 |
< |
try { |
285 |
< |
delay(LONG_DELAY_MS); |
286 |
< |
} catch(InterruptedException OK) { |
287 |
< |
} |
286 |
> |
done.await(LONG_DELAY_MS, MILLISECONDS); |
287 |
|
}}; |
288 |
|
|
289 |
|
List<Thread> threads = new ArrayList<>(); |
296 |
|
} |
297 |
|
for (Thread thread : threads) |
298 |
|
awaitTermination(thread); |
299 |
< |
for (ExecutorService executor : executors) |
301 |
< |
executor.shutdownNow(); // assumes shutdownNow interrupts threads |
299 |
> |
done.countDown(); |
300 |
|
for (ExecutorService executor : executors) |
301 |
|
joinPool(executor); |
302 |
|
} |