Package com.diozero.util
Class SleepUtil
- java.lang.Object
-
- com.diozero.util.SleepUtil
-
public class SleepUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description SleepUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
busySleep(long nanos)
Busy sleep for the specified number of nanoseconds.static void
sleepMillis(long millis)
Sleep for the specific number of millisecondsstatic long
sleepNanos(int seconds, long nanos)
Invoke the C nanosleep function via JNI.static void
sleepSeconds(double secs)
Sleep for the specific number of secondsstatic void
sleepSeconds(int secs)
Sleep for the specific number of seconds
-
-
-
Field Detail
-
MS_IN_SEC
public static final int MS_IN_SEC
- See Also:
- Constant Field Values
-
US_IN_SEC
public static final long US_IN_SEC
- See Also:
- Constant Field Values
-
NS_IN_SEC
public static final long NS_IN_SEC
- See Also:
- Constant Field Values
-
NS_IN_US
public static final int NS_IN_US
- See Also:
- Constant Field Values
-
US_IN_MS
public static final int US_IN_MS
- See Also:
- Constant Field Values
-
NS_IN_MS
public static final long NS_IN_MS
- See Also:
- Constant Field Values
-
-
Method Detail
-
sleepSeconds
public static void sleepSeconds(int secs) throws RuntimeInterruptedException
Sleep for the specific number of seconds- Parameters:
secs
- Number of seconds to sleep for- Throws:
RuntimeInterruptedException
- if interrupted
-
sleepSeconds
public static void sleepSeconds(double secs) throws RuntimeInterruptedException
Sleep for the specific number of seconds- Parameters:
secs
- Number of seconds to sleep for- Throws:
RuntimeInterruptedException
- if interrupted
-
sleepMillis
public static void sleepMillis(long millis) throws RuntimeInterruptedException
Sleep for the specific number of milliseconds- Parameters:
millis
- Number of milliseconds to sleep for- Throws:
RuntimeInterruptedException
- if interrupted
-
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 given the additional JNI overhead. Note - you must ensure that the diozero-system-utils library has been loaded vialoadSystemUtils()
prior to calling this method. The diozero APIs will do this on behalf of the application - this note is present for situations where such APIs have not yet been invoked. See C nanosleep man pages.- Parameters:
seconds
- seconds to sleep fornanos
- additional nanoseconds to sleep for; must be in the range 0 to 999999999- Returns:
- the remaining nanoseconds if interrupted
-
-