194 |
|
final CountDownLatch quittingTime = new CountDownLatch(1); |
195 |
|
final Callable<Void> awaiter = new CheckedCallable<Void>() { |
196 |
|
public Void realCall() throws InterruptedException { |
197 |
< |
quittingTime.await(); |
197 |
> |
assertTrue(quittingTime.await(2*LONG_DELAY_MS, MILLISECONDS)); |
198 |
|
return null; |
199 |
|
}}; |
200 |
|
final ExecutorService p |
201 |
|
= new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, |
202 |
|
new ArrayBlockingQueue<Runnable>(10)); |
203 |
< |
try (PoolCleaner cleaner = cleaner(p)) { |
204 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
203 |
> |
try (PoolCleaner cleaner = cleaner(p, quittingTime)) { |
204 |
> |
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
205 |
|
public void realRun() throws Exception { |
206 |
|
Future<Void> future = p.submit(awaiter); |
207 |
|
submitted.countDown(); |
208 |
|
future.get(); |
209 |
|
}}); |
210 |
< |
t.start(); |
211 |
< |
submitted.await(); |
210 |
> |
|
211 |
> |
await(submitted); |
212 |
|
t.interrupt(); |
213 |
< |
t.join(); |
214 |
< |
quittingTime.countDown(); |
213 |
> |
awaitTermination(t); |
214 |
|
} |
215 |
|
} |
216 |
|
|