Class SleepUtils

java.lang.Object
net.emustudio.emulib.SleepUtils

public final class SleepUtils extends Object
Precise sleeping.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Average duration of Thread.sleep(1) in nanoseconds (measured when the class is loaded).
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    preciseSleepNanos(long nanoDuration)
    Accurately sleeps on all platforms (Linux, Win, Mac); more precise than LockSupport.parkNanos.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SLEEP_PRECISION

      public static final long SLEEP_PRECISION
      Average duration of Thread.sleep(1) in nanoseconds (measured when the class is loaded).
  • Method Details

    • preciseSleepNanos

      public static void preciseSleepNanos(long nanoDuration)
      Accurately sleeps on all platforms (Linux, Win, Mac); more precise than LockSupport.parkNanos.

      Sleeps while the remaining time exceeds SLEEP_PRECISION, then spin-waits. Returns early if the thread is interrupted (the interrupt flag is kept). See alternative to Thread.sleep.

      Parameters:
      nanoDuration - nanoseconds