--- jsr166/src/test/tck/ExecutorsTest.java 2011/05/06 11:22:07 1.39 +++ jsr166/src/test/tck/ExecutorsTest.java 2011/05/27 19:28:38 1.40 @@ -6,7 +6,6 @@ * Pat Fisher, Mike Judd. */ - import junit.framework.*; import java.util.*; import java.util.concurrent.*; @@ -54,7 +53,6 @@ public class ExecutorsTest extends JSR16 } catch (NullPointerException success) {} } - /** * A new SingleThreadExecutor can execute runnables */ @@ -101,7 +99,6 @@ public class ExecutorsTest extends JSR16 } } - /** * A new newFixedThreadPool can execute runnables */ @@ -144,7 +141,6 @@ public class ExecutorsTest extends JSR16 } catch (IllegalArgumentException success) {} } - /** * An unconfigurable newFixedThreadPool can execute runnables */ @@ -176,7 +172,6 @@ public class ExecutorsTest extends JSR16 } catch (NullPointerException success) {} } - /** * a newSingleThreadScheduledExecutor successfully runs delayed task */ @@ -252,34 +247,33 @@ public class ExecutorsTest extends JSR16 * Future.get on submitted tasks will time out if they compute too long. */ public void testTimedCallable() throws Exception { + final ExecutorService[] executors = { + Executors.newSingleThreadExecutor(), + Executors.newCachedThreadPool(), + Executors.newFixedThreadPool(2), + Executors.newScheduledThreadPool(2), + }; + final Runnable sleeper = new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { delay(LONG_DELAY_MS); }}; - for (ExecutorService executor : - new ExecutorService[] { - Executors.newSingleThreadExecutor(), - Executors.newCachedThreadPool(), - Executors.newFixedThreadPool(2), - Executors.newScheduledThreadPool(2), - }) { - try { - Future future = executor.submit(sleeper); - try { - future.get(SHORT_DELAY_MS, MILLISECONDS); - shouldThrow(); - } catch (TimeoutException success) { - } finally { - future.cancel(true); - } - } - finally { - joinPool(executor); - } + + List threads = new ArrayList(); + for (final ExecutorService executor : executors) { + threads.add(newStartedThread(new CheckedRunnable() { + public void realRun() { + long startTime = System.nanoTime(); + Future future = executor.submit(sleeper); + assertFutureTimesOut(future); + }})); } + for (Thread thread : threads) + awaitTermination(thread); + for (ExecutorService executor : executors) + joinPool(executor); } - /** * ThreadPoolExecutor using defaultThreadFactory has * specified group, priority, daemon status, and name @@ -387,7 +381,6 @@ public class ExecutorsTest extends JSR16 } } - /** * Without class loader permissions, creating * privilegedCallableUsingCurrentClassLoader throws ACE @@ -543,7 +536,6 @@ public class ExecutorsTest extends JSR16 assertSame(one, c.call()); } - /** * callable(null Runnable) throws NPE */ @@ -584,5 +576,4 @@ public class ExecutorsTest extends JSR16 } catch (NullPointerException success) {} } - }