< prev index next >

test/jdk/java/util/concurrent/tck/ThreadLocalRandomTest.java

Print this page
8234131: Miscellaneous changes imported from jsr166 CVS 2020-12
Reviewed-by: martin

*** 382,412 **** // be polluted by previous tests. final AtomicReference<ThreadLocalRandom> threadLocalRandom = new AtomicReference<>(); final AtomicLong rand = new AtomicLong(); - long firstRand = 0; - ThreadLocalRandom firstThreadLocalRandom = null; - Runnable getRandomState = new CheckedRunnable() { public void realRun() { ThreadLocalRandom current = ThreadLocalRandom.current(); assertSame(current, ThreadLocalRandom.current()); - // test bug: the following is not guaranteed and not true in JDK8 - // assertNotSame(current, threadLocalRandom.get()); rand.set(current.nextLong()); threadLocalRandom.set(current); }}; ! Thread first = newStartedThread(getRandomState); ! awaitTermination(first); ! firstRand = rand.get(); ! firstThreadLocalRandom = threadLocalRandom.get(); for (int i = 0; i < NCALLS; i++) { ! Thread t = newStartedThread(getRandomState); ! awaitTermination(t); if (firstRand != rand.get()) return; } fail("all threads generate the same pseudo-random sequence"); } --- 382,409 ---- // be polluted by previous tests. final AtomicReference<ThreadLocalRandom> threadLocalRandom = new AtomicReference<>(); final AtomicLong rand = new AtomicLong(); Runnable getRandomState = new CheckedRunnable() { public void realRun() { ThreadLocalRandom current = ThreadLocalRandom.current(); assertSame(current, ThreadLocalRandom.current()); rand.set(current.nextLong()); threadLocalRandom.set(current); }}; ! awaitTermination(newStartedThread(getRandomState)); ! long firstRand = rand.get(); ! ThreadLocalRandom firstThreadLocalRandom = threadLocalRandom.get(); ! assertNotNull(firstThreadLocalRandom); for (int i = 0; i < NCALLS; i++) { ! awaitTermination(newStartedThread(getRandomState)); ! if (testImplementationDetails) ! // ThreadLocalRandom has been a singleton since jdk8. ! assertSame(firstThreadLocalRandom, threadLocalRandom.get()); if (firstRand != rand.get()) return; } fail("all threads generate the same pseudo-random sequence"); }
< prev index next >