--- jsr166/src/test/loops/ContextSwitchTest.java 2009/10/29 23:09:07 1.4 +++ jsr166/src/test/loops/ContextSwitchTest.java 2015/10/12 20:16:47 1.9 @@ -1,16 +1,16 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ +import java.util.*; import java.util.concurrent.*; -import java.util.concurrent.locks.*; import java.util.concurrent.atomic.*; -import java.util.*; +import java.util.concurrent.locks.*; public final class ContextSwitchTest { - final static int iters = 1000000; + static final int iters = 1000000; static AtomicReference turn = new AtomicReference(); public static void main(String[] args) throws Exception { test(); @@ -37,6 +37,13 @@ public final class ContextSwitchTest { } static final class MyThread extends Thread { + + static { + // Reduce the risk of rare disastrous classloading in first call to + // LockSupport.park: https://bugs.openjdk.java.net/browse/JDK-8074773 + Class ensureLoaded = LockSupport.class; + } + volatile Thread other; volatile int nparks; @@ -56,7 +63,6 @@ public final class ContextSwitchTest { LockSupport.unpark(other); nparks = p; System.out.println("parks: " + p); - } } }