--- jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2011/05/07 19:49:37 1.28 +++ jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2011/05/27 19:35:24 1.29 @@ -115,7 +115,6 @@ public class ThreadPoolExecutorSubclassT } } - static class CustomTPE extends ThreadPoolExecutor { protected RunnableFuture newTaskFor(Callable c) { return new CustomTask(c); @@ -188,7 +187,6 @@ public class ThreadPoolExecutorSubclassT } } - /** * execute successfully executes a runnable */ @@ -315,7 +313,6 @@ public class ThreadPoolExecutorSubclassT joinPool(p); } - /** * getThreadFactory returns factory in constructor if not set */ @@ -337,7 +334,6 @@ public class ThreadPoolExecutorSubclassT joinPool(p); } - /** * setThreadFactory(null) throws NPE */ @@ -374,7 +370,6 @@ public class ThreadPoolExecutorSubclassT joinPool(p); } - /** * setRejectedExecutionHandler(null) throws NPE */ @@ -389,7 +384,6 @@ public class ThreadPoolExecutorSubclassT } } - /** * getLargestPoolSize increases, but doesn't overestimate, when * multiple threads active @@ -495,7 +489,6 @@ public class ThreadPoolExecutorSubclassT joinPool(p); } - /** * isTerminated is false before termination, true after */ @@ -689,7 +682,6 @@ public class ThreadPoolExecutorSubclassT // Exception Tests - /** * Constructor throws if corePoolSize argument is less than zero */ @@ -750,8 +742,6 @@ public class ThreadPoolExecutorSubclassT } catch (NullPointerException success) {} } - - /** * Constructor throws if corePoolSize argument is less than zero */ @@ -823,7 +813,6 @@ public class ThreadPoolExecutorSubclassT } catch (NullPointerException success) {} } - /** * Constructor throws if corePoolSize argument is less than zero */ @@ -895,7 +884,6 @@ public class ThreadPoolExecutorSubclassT } catch (NullPointerException success) {} } - /** * Constructor throws if corePoolSize argument is less than zero */ @@ -981,7 +969,6 @@ public class ThreadPoolExecutorSubclassT } catch (NullPointerException success) {} } - /** * execute throws RejectedExecutionException if saturated. */ @@ -1131,7 +1118,6 @@ public class ThreadPoolExecutorSubclassT } } - /** * execute using DiscardOldestPolicy drops task on shutdown */ @@ -1149,7 +1135,6 @@ public class ThreadPoolExecutorSubclassT } } - /** * execute(null) throws NPE */ @@ -1214,7 +1199,6 @@ public class ThreadPoolExecutorSubclassT joinPool(p); } - /** * setKeepAliveTime throws IllegalArgumentException * when given a negative value @@ -1303,7 +1287,6 @@ public class ThreadPoolExecutorSubclassT } } - /** * invokeAny(null) throws NPE */ @@ -1465,8 +1448,6 @@ public class ThreadPoolExecutorSubclassT } } - - /** * timed invokeAny(null) throws NPE */ @@ -1726,9 +1707,10 @@ public class ThreadPoolExecutorSubclassT * allowCoreThreadTimeOut(true) causes idle threads to time out */ public void testAllowCoreThreadTimeOut_true() throws Exception { + long coreThreadTimeOut = SHORT_DELAY_MS; final ThreadPoolExecutor p = new CustomTPE(2, 10, - SHORT_DELAY_MS, MILLISECONDS, + coreThreadTimeOut, MILLISECONDS, new ArrayBlockingQueue(10)); final CountDownLatch threadStarted = new CountDownLatch(1); try { @@ -1738,12 +1720,13 @@ public class ThreadPoolExecutorSubclassT threadStarted.countDown(); assertEquals(1, p.getPoolSize()); }}); - assertTrue(threadStarted.await(SMALL_DELAY_MS, MILLISECONDS)); - for (int i = 0; i < (MEDIUM_DELAY_MS/10); i++) { - if (p.getPoolSize() == 0) - break; - delay(10); - } + await(threadStarted); + delay(coreThreadTimeOut); + long startTime = System.nanoTime(); + while (p.getPoolSize() > 0 + && millisElapsedSince(startTime) < LONG_DELAY_MS) + Thread.yield(); + assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); assertEquals(0, p.getPoolSize()); } finally { joinPool(p); @@ -1754,9 +1737,10 @@ public class ThreadPoolExecutorSubclassT * allowCoreThreadTimeOut(false) causes idle threads not to time out */ public void testAllowCoreThreadTimeOut_false() throws Exception { + long coreThreadTimeOut = SHORT_DELAY_MS; final ThreadPoolExecutor p = new CustomTPE(2, 10, - SHORT_DELAY_MS, MILLISECONDS, + coreThreadTimeOut, MILLISECONDS, new ArrayBlockingQueue(10)); final CountDownLatch threadStarted = new CountDownLatch(1); try { @@ -1766,7 +1750,7 @@ public class ThreadPoolExecutorSubclassT threadStarted.countDown(); assertTrue(p.getPoolSize() >= 1); }}); - delay(SMALL_DELAY_MS); + delay(2 * coreThreadTimeOut); assertTrue(p.getPoolSize() >= 1); } finally { joinPool(p);