Class SleepUtil


  • public class SleepUtil
    extends Object
    • Constructor Detail

      • SleepUtil

        public SleepUtil()
    • Method Detail

      • busySleep

        public static void busySleep​(long nanos)
        Busy sleep for the specified number of nanoseconds. It is the caller's responsibility to factor in any delays associated with calling this method - this could be as much as 1.5 microseconds on a Raspberry Pi 4. Warning - this will consume 100% of one core, use with caution and only with small delays.
        Parameters:
        nanos - The period to delay for
      • sleepNanos

        public static long sleepNanos​(int seconds,
                                      long nanos)
        Invoke the C nanosleep function via JNI. Note that the accuracy of the sleep is not guaranteed - the delta could be as much as 30 microseconds. Note - you must ensure that the diozero-system-utils library has been loaded via loadSystemUtils() prior to calling this method. See C nanosleep man pages.
        Parameters:
        seconds - seconds to sleep for
        nanos - additional nanoseconds to sleep for; must be in the range 0 to 999999999
        Returns:
        the remaining nanoseconds if interrupted