--- jsr166/src/test/tck/ThreadPoolExecutorTest.java 2011/05/07 19:49:37 1.43 +++ jsr166/src/test/tck/ThreadPoolExecutorTest.java 2011/05/27 19:35:24 1.44 @@ -46,7 +46,6 @@ public class ThreadPoolExecutorTest exte } } - /** * execute successfully executes a runnable */ @@ -185,7 +184,6 @@ public class ThreadPoolExecutorTest exte joinPool(p); } - /** * getThreadFactory returns factory in constructor if not set */ @@ -215,7 +213,6 @@ public class ThreadPoolExecutorTest exte joinPool(p); } - /** * setThreadFactory(null) throws NPE */ @@ -262,7 +259,6 @@ public class ThreadPoolExecutorTest exte joinPool(p); } - /** * setRejectedExecutionHandler(null) throws NPE */ @@ -280,7 +276,6 @@ public class ThreadPoolExecutorTest exte } } - /** * getLargestPoolSize increases, but doesn't overestimate, when * multiple threads active @@ -391,7 +386,6 @@ public class ThreadPoolExecutorTest exte joinPool(p); } - /** * isTerminated is false before termination, true after */ @@ -587,7 +581,6 @@ public class ThreadPoolExecutorTest exte // Exception Tests - /** * Constructor throws if corePoolSize argument is less than zero */ @@ -660,8 +653,6 @@ public class ThreadPoolExecutorTest exte } catch (NullPointerException success) {} } - - /** * Constructor throws if corePoolSize argument is less than zero */ @@ -753,7 +744,6 @@ public class ThreadPoolExecutorTest exte } catch (NullPointerException success) {} } - /** * Constructor throws if corePoolSize argument is less than zero */ @@ -845,7 +835,6 @@ public class ThreadPoolExecutorTest exte } catch (NullPointerException success) {} } - /** * Constructor throws if corePoolSize argument is less than zero */ @@ -1212,7 +1201,6 @@ public class ThreadPoolExecutorTest exte } } - /** * execute using DiscardOldestPolicy drops task on shutdown */ @@ -1234,7 +1222,6 @@ public class ThreadPoolExecutorTest exte } } - /** * execute(null) throws NPE */ @@ -1307,7 +1294,6 @@ public class ThreadPoolExecutorTest exte joinPool(p); } - /** * setKeepAliveTime throws IllegalArgumentException * when given a negative value @@ -1406,7 +1392,6 @@ public class ThreadPoolExecutorTest exte } } - /** * invokeAny(null) throws NPE */ @@ -1600,8 +1585,6 @@ public class ThreadPoolExecutorTest exte } } - - /** * timed invokeAny(null) throws NPE */ @@ -1903,24 +1886,26 @@ public class ThreadPoolExecutorTest exte * allowCoreThreadTimeOut(true) causes idle threads to time out */ public void testAllowCoreThreadTimeOut_true() throws Exception { + long coreThreadTimeOut = SHORT_DELAY_MS; final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 10, - SHORT_DELAY_MS, MILLISECONDS, + coreThreadTimeOut, MILLISECONDS, new ArrayBlockingQueue(10)); final CountDownLatch threadStarted = new CountDownLatch(1); try { p.allowCoreThreadTimeOut(true); p.execute(new CheckedRunnable() { - public void realRun() throws InterruptedException { + public void realRun() { 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); @@ -1931,9 +1916,10 @@ public class ThreadPoolExecutorTest exte * allowCoreThreadTimeOut(false) causes idle threads not to time out */ public void testAllowCoreThreadTimeOut_false() throws Exception { + long coreThreadTimeOut = SHORT_DELAY_MS; final ThreadPoolExecutor p = new ThreadPoolExecutor(2, 10, - SHORT_DELAY_MS, MILLISECONDS, + coreThreadTimeOut, MILLISECONDS, new ArrayBlockingQueue(10)); final CountDownLatch threadStarted = new CountDownLatch(1); try { @@ -1943,7 +1929,7 @@ public class ThreadPoolExecutorTest exte threadStarted.countDown(); assertTrue(p.getPoolSize() >= 1); }}); - delay(SMALL_DELAY_MS); + delay(2 * coreThreadTimeOut); assertTrue(p.getPoolSize() >= 1); } finally { joinPool(p);