16 |
|
|
17 |
|
public class AbstractExecutorServiceTest extends JSR166TestCase { |
18 |
|
public static void main(String[] args) { |
19 |
< |
junit.textui.TestRunner.run (suite()); |
19 |
> |
junit.textui.TestRunner.run(suite()); |
20 |
|
} |
21 |
|
public static Test suite() { |
22 |
|
return new TestSuite(AbstractExecutorServiceTest.class); |
212 |
|
|
213 |
|
|
214 |
|
/** |
215 |
< |
* Blocking on submit(callable) throws InterruptedException if |
216 |
< |
* caller interrupted. |
215 |
> |
* submit(callable).get() throws InterruptedException if interrupted |
216 |
|
*/ |
217 |
|
public void testInterruptedSubmit() throws InterruptedException { |
218 |
< |
final ThreadPoolExecutor p = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(10)); |
219 |
< |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
220 |
< |
public void realRun() throws Exception { |
221 |
< |
p.submit(new CheckedCallable<Object>() { |
222 |
< |
public Object realCall() |
223 |
< |
throws InterruptedException { |
224 |
< |
Thread.sleep(SMALL_DELAY_MS); |
225 |
< |
return null; |
226 |
< |
}}).get(); |
227 |
< |
}}); |
228 |
< |
|
229 |
< |
t.start(); |
230 |
< |
Thread.sleep(SHORT_DELAY_MS); |
231 |
< |
t.interrupt(); |
232 |
< |
joinPool(p); |
218 |
> |
final CountDownLatch submitted = new CountDownLatch(1); |
219 |
> |
final CountDownLatch quittingTime = new CountDownLatch(1); |
220 |
> |
final ExecutorService p |
221 |
> |
= new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS, |
222 |
> |
new ArrayBlockingQueue<Runnable>(10)); |
223 |
> |
final Callable<Void> awaiter = new CheckedCallable<Void>() { |
224 |
> |
public Void realCall() throws InterruptedException { |
225 |
> |
quittingTime.await(); |
226 |
> |
return null; |
227 |
> |
}}; |
228 |
> |
try { |
229 |
> |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
230 |
> |
public void realRun() throws Exception { |
231 |
> |
Future<Void> future = p.submit(awaiter); |
232 |
> |
submitted.countDown(); |
233 |
> |
future.get(); |
234 |
> |
}}); |
235 |
> |
t.start(); |
236 |
> |
submitted.await(); |
237 |
> |
t.interrupt(); |
238 |
> |
t.join(); |
239 |
> |
} finally { |
240 |
> |
quittingTime.countDown(); |
241 |
> |
joinPool(p); |
242 |
> |
} |
243 |
|
} |
244 |
|
|
245 |
|
/** |