--- jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2015/10/05 22:09:02 1.86 +++ jsr166/src/test/tck/ThreadPoolExecutorSubclassTest.java 2015/10/06 05:12:16 1.89 @@ -260,7 +260,7 @@ public class ThreadPoolExecutorSubclassT public void realRun() throws InterruptedException { threadStarted.countDown(); assertEquals(1, p.getActiveCount()); - done.await(); + await(done); }}); assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(1, p.getActiveCount()); @@ -476,24 +476,23 @@ public class ThreadPoolExecutorSubclassT */ public void testGetLargestPoolSize() throws InterruptedException { final int THREADS = 3; + final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new CustomTPE(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 { threadsStarted.countDown(); - done.await(); + await(done); assertEquals(THREADS, p.getLargestPoolSize()); }}); assertTrue(threadsStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(THREADS, p.getLargestPoolSize()); - done.countDown(); // release pool } assertEquals(THREADS, p.getLargestPoolSize()); } @@ -521,23 +520,22 @@ public class ThreadPoolExecutorSubclassT * become active */ public void testGetPoolSize() throws InterruptedException { + final CountDownLatch done = new CountDownLatch(1); final ThreadPoolExecutor p = new CustomTPE(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(); + await(done); }}); assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(1, p.getPoolSize()); - done.countDown(); // release pool } } @@ -558,7 +556,7 @@ public class ThreadPoolExecutorSubclassT p.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); - done.await(); + await(done); }}); assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertEquals(1, p.getTaskCount()); @@ -569,7 +567,7 @@ public class ThreadPoolExecutorSubclassT public void realRun() throws InterruptedException { threadStarted.countDown(); assertEquals(1 + TASKS, p.getTaskCount()); - done.await(); + await(done); }}); } assertEquals(1 + TASKS, p.getTaskCount()); @@ -610,7 +608,7 @@ public class ThreadPoolExecutorSubclassT public void realRun() throws InterruptedException { assertFalse(p.isTerminating()); threadStarted.countDown(); - done.await(); + await(done); }}); assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertFalse(p.isTerminating()); @@ -638,7 +636,7 @@ public class ThreadPoolExecutorSubclassT public void realRun() throws InterruptedException { assertFalse(p.isTerminating()); threadStarted.countDown(); - done.await(); + await(done); }}); assertTrue(threadStarted.await(LONG_DELAY_MS, MILLISECONDS)); assertFalse(p.isTerminating()); @@ -668,7 +666,7 @@ public class ThreadPoolExecutorSubclassT public Boolean realCall() throws InterruptedException { threadStarted.countDown(); assertSame(q, p.getQueue()); - done.await(); + await(done); return Boolean.TRUE; }}; tasks[i] = new FutureTask(task); @@ -700,7 +698,7 @@ public class ThreadPoolExecutorSubclassT tasks[i] = new CheckedRunnable() { public void realRun() throws InterruptedException { threadStarted.countDown(); - done.await(); + await(done); }}; p.execute(tasks[i]); } @@ -735,7 +733,7 @@ public class ThreadPoolExecutorSubclassT Callable task = new CheckedCallable() { public Boolean realCall() throws InterruptedException { threadStarted.countDown(); - done.await(); + await(done); return Boolean.TRUE; }}; tasks[i] = new FutureTask(task); @@ -1146,7 +1144,7 @@ public class ThreadPoolExecutorSubclassT final CountDownLatch done = new CountDownLatch(1); Runnable task = new CheckedRunnable() { public void realRun() throws InterruptedException { - done.await(); + await(done); }}; for (int i = 0; i < 2; ++i) p.execute(task); @@ -1174,7 +1172,7 @@ public class ThreadPoolExecutorSubclassT final CountDownLatch done = new CountDownLatch(1); Runnable blocker = new CheckedRunnable() { public void realRun() throws InterruptedException { - done.await(); + await(done); }}; p.execute(blocker); TrackedNoOpRunnable[] tasks = new TrackedNoOpRunnable[5]; @@ -1842,7 +1840,7 @@ public class ThreadPoolExecutorSubclassT 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();