--- jsr166/src/test/tck/ForkJoinTask8Test.java 2015/09/09 00:26:59 1.16 +++ jsr166/src/test/tck/ForkJoinTask8Test.java 2015/10/06 05:56:01 1.21 @@ -74,7 +74,7 @@ public class ForkJoinTask8Test extends J } private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) { - try { + try (PoolCleaner cleaner = cleaner(pool)) { assertFalse(a.isDone()); assertFalse(a.isCompletedNormally()); assertFalse(a.isCompletedAbnormally()); @@ -90,8 +90,6 @@ public class ForkJoinTask8Test extends J assertFalse(a.isCancelled()); assertNull(a.getException()); assertNull(a.getRawResult()); - } finally { - joinPool(pool); } } @@ -128,17 +126,17 @@ public class ForkJoinTask8Test extends J { Thread.currentThread().interrupt(); - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); assertSame(expected, a.join()); - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); Thread.interrupted(); } { Thread.currentThread().interrupt(); - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); Thread.interrupted(); } @@ -174,9 +172,9 @@ public class ForkJoinTask8Test extends J Thread.interrupted(); { - long t0 = System.nanoTime(); + long startTime = System.nanoTime(); a.quietlyJoin(); // should be no-op - assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); } try { @@ -200,9 +198,9 @@ public class ForkJoinTask8Test extends J abstract static class BinaryAsyncAction extends ForkJoinTask { - private BinaryAsyncAction parent; + private volatile BinaryAsyncAction parent; - private BinaryAsyncAction sibling; + private volatile BinaryAsyncAction sibling; protected BinaryAsyncAction() { setForkJoinTaskTag(INITIAL_STATE); @@ -1165,13 +1163,14 @@ public class ForkJoinTask8Test extends J final ForkJoinTask b = ForkJoinTask.adapt(awaiter(done)); final ForkJoinTask c = ForkJoinTask.adapt(awaiter(done)); final ForkJoinPool p = singletonPool(); - Thread external = new Thread() { - public void run() { + try (PoolCleaner cleaner = cleaner(p, done)) { + Thread external = new Thread(new CheckedRunnable() { + public void realRun() { p.execute(a); p.execute(b); p.execute(c); - }}; - RecursiveAction s = new CheckedRecursiveAction() { + }}); + RecursiveAction s = new CheckedRecursiveAction() { protected void realCompute() { external.start(); try { @@ -1185,11 +1184,7 @@ public class ForkJoinTask8Test extends J assertTrue(r == a || r == b || r == c); assertFalse(r.isDone()); }}; - try { p.invoke(s); - } finally { - done.countDown(); - joinPool(p); } }