From b5d355ac84ded85d689c08e2c3c16a67f63d0023 Mon Sep 17 00:00:00 2001
From: Doug Lea
Date: Thu, 3 Mar 2016 10:46:22 -0800
Subject: [PATCH] 8150416: Miscellaneous changes imported from jsr166 CVS
2016-03
Reviewed-by: martin, psandoz
---
.../util/concurrent/tck/Collection8Test.java | 40 ++++++++++---------
.../java/util/concurrent/tck/ThreadTest.java | 2 +-
2 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/jdk/test/java/util/concurrent/tck/Collection8Test.java b/jdk/test/java/util/concurrent/tck/Collection8Test.java
index 1a10b280228..36f99e157dc 100644
--- a/jdk/test/java/util/concurrent/tck/Collection8Test.java
+++ b/jdk/test/java/util/concurrent/tck/Collection8Test.java
@@ -37,6 +37,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@@ -98,26 +99,29 @@ public class Collection8Test extends JSR166TestCase {
public void testForEachConcurrentStressTest() throws Throwable {
if (!impl.isConcurrent()) return;
final Collection c = impl.emptyCollection();
- final long testDurationMillis = SHORT_DELAY_MS;
+ final long testDurationMillis = timeoutMillis();
final AtomicBoolean done = new AtomicBoolean(false);
final Object elt = impl.makeElement(1);
- ExecutorService pool = Executors.newCachedThreadPool();
- Runnable checkElt = () -> {
- while (!done.get())
- c.stream().forEach((x) -> { assertSame(x, elt); }); };
- Runnable addRemove = () -> {
- while (!done.get()) {
- assertTrue(c.add(elt));
- assertTrue(c.remove(elt));
- }};
- Future> f1 = pool.submit(checkElt);
- Future> f2 = pool.submit(addRemove);
- Thread.sleep(testDurationMillis);
- done.set(true);
- pool.shutdown();
- assertTrue(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
- assertNull(f1.get(LONG_DELAY_MS, MILLISECONDS));
- assertNull(f2.get(LONG_DELAY_MS, MILLISECONDS));
+ final Future> f1, f2;
+ final ExecutorService pool = Executors.newCachedThreadPool();
+ try (PoolCleaner cleaner = cleaner(pool, done)) {
+ final CountDownLatch threadsStarted = new CountDownLatch(2);
+ Runnable checkElt = () -> {
+ threadsStarted.countDown();
+ while (!done.get())
+ c.stream().forEach((x) -> { assertSame(x, elt); }); };
+ Runnable addRemove = () -> {
+ threadsStarted.countDown();
+ while (!done.get()) {
+ assertTrue(c.add(elt));
+ assertTrue(c.remove(elt));
+ }};
+ f1 = pool.submit(checkElt);
+ f2 = pool.submit(addRemove);
+ Thread.sleep(testDurationMillis);
+ }
+ assertNull(f1.get(0L, MILLISECONDS));
+ assertNull(f2.get(0L, MILLISECONDS));
}
// public void testCollection8DebugFail() { fail(); }
diff --git a/jdk/test/java/util/concurrent/tck/ThreadTest.java b/jdk/test/java/util/concurrent/tck/ThreadTest.java
index 939d590beb9..92b2aca52a6 100644
--- a/jdk/test/java/util/concurrent/tck/ThreadTest.java
+++ b/jdk/test/java/util/concurrent/tck/ThreadTest.java
@@ -77,7 +77,7 @@ public class ThreadTest extends JSR166TestCase {
*/
public void testGetAndSetDefaultUncaughtExceptionHandler() {
assertEquals(null, Thread.getDefaultUncaughtExceptionHandler());
- // failure due to securityException is OK.
+ // failure due to SecurityException is OK.
// Would be nice to explicitly test both ways, but cannot yet.
Thread.UncaughtExceptionHandler defaultHandler
= Thread.getDefaultUncaughtExceptionHandler();