--- jsr166/src/test/tck/ThreadPoolExecutorTest.java 2015/10/05 21:54:33 1.101 +++ jsr166/src/test/tck/ThreadPoolExecutorTest.java 2015/10/06 00:41:47 1.105 @@ -115,7 +115,7 @@ public class ThreadPoolExecutorTest exte assertEquals(1, p.getActiveCount()); done.await(); }}); - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(1, p.getActiveCount()); done.countDown(); } @@ -329,14 +329,14 @@ public class ThreadPoolExecutorTest exte */ public void testGetLargestPoolSize() throws InterruptedException { final int THREADS = 3; + final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(THREADS, THREADS, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); - try (PoolCleaner cleaner = cleaner(p)) { - final CountDownLatch threadsStarted = new CountDownLatch(THREADS); - final CountDownLatch done = new CountDownLatch(1); + try (PoolCleaner cleaner = cleaner(p, done)) { assertEquals(0, p.getLargestPoolSize()); + final CountDownLatch threadsStarted = new CountDownLatch(THREADS); for (int i = 0; i < THREADS; i++) p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { @@ -344,9 +344,8 @@ public class ThreadPoolExecutorTest exte done.await(); assertEquals(THREADS, p.getLargestPoolSize()); }}); - assertTrue(threadsStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(THREADS, p.getLargestPoolSize()); - done.countDown(); // release pool } assertEquals(THREADS, p.getLargestPoolSize()); } @@ -374,23 +373,22 @@ public class ThreadPoolExecutorTest exte * become active */ public void testGetPoolSize() throws InterruptedException { + final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, LONG_DELAY_MS, MILLISECONDS, new ArrayBlockingQueue(10)); - try (PoolCleaner cleaner = cleaner(p)) { - final CountDownLatch threadStarted = new CountDownLatch(1); - final CountDownLatch done = new CountDownLatch(1); + try (PoolCleaner cleaner = cleaner(p, done)) { assertEquals(0, p.getPoolSize()); + final CountDownLatch threadStarted = new CountDownLatch(1); p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); assertEquals(1, p.getPoolSize()); done.await(); }}); - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(1, p.getPoolSize()); - done.countDown(); // release pool } } @@ -497,7 +495,7 @@ public class ThreadPoolExecutorTest exte threadStarted.countDown(); done.await(); }}); - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertFalse(p.isTerminating()); done.countDown(); try { p.shutdown(); } catch (SecurityException ok) { return; } @@ -525,7 +523,7 @@ public class ThreadPoolExecutorTest exte threadStarted.countDown(); done.await(); }}); - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertFalse(p.isTerminating()); done.countDown(); try { p.shutdown(); } catch (SecurityException ok) { return; } @@ -559,7 +557,7 @@ public class ThreadPoolExecutorTest exte tasks[i] = new FutureTask(task); p.execute(tasks[i]); } - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertSame(q, p.getQueue()); assertFalse(q.contains(tasks[0])); assertTrue(q.contains(tasks[tasks.length - 1])); @@ -589,7 +587,7 @@ public class ThreadPoolExecutorTest exte }}; p.execute(tasks[i]); } - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertFalse(p.remove(tasks[0])); assertTrue(q.contains(tasks[4])); assertTrue(q.contains(tasks[3])); @@ -1026,14 +1024,14 @@ public class ThreadPoolExecutorTest exte * get of submitted callable throws InterruptedException if interrupted */ public void testInterruptedSubmit() throws InterruptedException { + final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new ThreadPoolExecutor(1, 1, 60, SECONDS, new ArrayBlockingQueue(10)); - try (PoolCleaner cleaner = cleaner(p)) { + try (PoolCleaner cleaner = cleaner(p, done)) { final CountDownLatch threadStarted = new CountDownLatch(1); - final CountDownLatch done = new CountDownLatch(1); Thread t = newStartedThread(new CheckedInterruptedRunnable() { public void realRun() throws Exception { Callable task = new CheckedCallable() { @@ -1045,10 +1043,9 @@ public class ThreadPoolExecutorTest exte p.submit(task).get(); }}); - assertTrue(threadStarted.await(MEDIUM_DELAY_MS, MILLISECONDS)); + await(threadStarted); t.interrupt(); - awaitTermination(t, MEDIUM_DELAY_MS); - done.countDown(); + awaitTermination(t); } } @@ -1846,7 +1843,7 @@ public class ThreadPoolExecutorTest exte List> l = new ArrayList>(); l.add(new NPETask()); List> futures = - e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); + e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS); assertEquals(1, futures.size()); try { futures.get(0).get();