OnSpinWaitJDK8Adapter { static boolean onSpinWaitOrNothing() { if (ON_SPIN_WAIT_HANDLE != null) { try { ON_SPIN_WAIT_HANDLE.invokeExact(); return true; } catch (Throwable ignore) { } } return false; } private  OnSpinWaitJDK8Adapter();   }
@Test void example_1() throws Exception { while (!flag.compareAndSet(false, true)) { OnSpinWaitJDK8Adapter.onSpinWaitOrNothing(); } }
@Test void example_2() throws Exception { while (!flag.compareAndSet(false, true)) { if (!OnSpinWaitJDK8Adapter.onSpinWaitOrNothing()) { } } }