@Test public void testParkNanosSafeLong() { final long sleepFor = 50; for (int i = 0; i < 10; i++) { final long start = System.nanoTime(); ThreadUtil.parkNanosSafe(sleepFor); final long stop = System.nanoTime(); final long duration = stop - start; assertTrue("Not slept enough: " + duration + "ns < " + sleepFor + "ns!!!", duration > sleepFor); } }
public static void parkNanosSafe(final long sleepTotal) { final long sleepStart = System.nanoTime(); long stillSleep = sleepTotal; do { LockSupport.parkNanos(stillSleep); long timeSinceStart = System.nanoTime() - sleepStart; stillSleep = sleepTotal - timeSinceStart; } while (stillSleep > 0); }
ThreadUtil { public static void parkNanosSafe(final long sleepTotal) { final long sleepStart = System.nanoTime(); long stillSleep = sleepTotal; do { LockSupport.parkNanos(stillSleep); long timeSinceStart = System.nanoTime() - sleepStart; stillSleep = sleepTotal - timeSinceStart; } while (stillSleep > 0); } }
ThreadUtil { public static void parkNanosSafe(final long sleepTotal) { final long sleepStart = System.nanoTime(); long stillSleep = sleepTotal; do { LockSupport.parkNanos(stillSleep); long timeSinceStart = System.nanoTime() - sleepStart; stillSleep = sleepTotal - timeSinceStart; } while (stillSleep > 0); } private  ThreadUtil(); }
ThreadUtil { public static void parkNanosSafe(final long sleepTotal) { final long sleepStart = System.nanoTime(); long stillSleep = sleepTotal; do { LockSupport.parkNanos(stillSleep); long timeSinceStart = System.nanoTime() - sleepStart; stillSleep = sleepTotal - timeSinceStart; } while (stillSleep > 0); } private  ThreadUtil(); static void parkNanosSafe(final long sleepTotal); static boolean parkNanosSafe(final long sleepTotal, final AtomicBoolean cancelSwitch); }
ThreadUtil { public static void parkNanosSafe(final long sleepTotal) { final long sleepStart = System.nanoTime(); long stillSleep = sleepTotal; do { LockSupport.parkNanos(stillSleep); long timeSinceStart = System.nanoTime() - sleepStart; stillSleep = sleepTotal - timeSinceStart; } while (stillSleep > 0); } private  ThreadUtil(); static void parkNanosSafe(final long sleepTotal); static boolean parkNanosSafe(final long sleepTotal, final AtomicBoolean cancelSwitch);  }