--- jsr166/src/test/tck/ThreadLocalRandom8Test.java 2015/04/25 04:55:31 1.9 +++ jsr166/src/test/tck/ThreadLocalRandom8Test.java 2017/08/04 03:30:21 1.12 @@ -232,4 +232,20 @@ public class ThreadLocalRandom8Test exte assertEquals(size, counter.sum()); } + /** + * A deserialized/reserialized ThreadLocalRandom is always + * identical to ThreadLocalRandom.current() + */ + public void testSerialization() { + assertSame( + ThreadLocalRandom.current(), + serialClone(ThreadLocalRandom.current())); + // In the current implementation, there is exactly one shared instance + if (testImplementationDetails) + assertSame( + ThreadLocalRandom.current(), + java.util.concurrent.CompletableFuture.supplyAsync( + () -> serialClone(ThreadLocalRandom.current())).join()); + } + }