Java Utililty Methods Sleep

List of utility methods to do Sleep

Description

The list of methods to do Sleep are organized into topic(s).

Method

voidsleepNoShit(long nanos)
sleep No Shit
if (nanos < 0)
    return;
try {
    Thread.sleep(nanos / 1000000, (int) (nanos % 1000000));
} catch (InterruptedException e) {
voidsleepNotException(long millis)
sleep Not Exception
try {
    Thread.sleep(millis);
} catch (Exception ex) {
    System.out.println("sleep ex," + ex.getClass().getSimpleName());
voidsleepNoThrow(long timeoutMs)
sleep No Throw
try {
    Thread.sleep(timeoutMs);
} catch (InterruptedException e) {
voidsleepNs(int ns)
sleep Ns
long start = System.nanoTime();
long end = 0;
do {
    end = System.nanoTime();
} while (start + ns >= end);
voidsleepNS(long ns)
sleep NS
if (ns <= 0) {
    throwIfInterrupted();
    return;
long millis = ns / 1000000;
int nanos = (int) (ns - millis * 1000000);
Thread.sleep(millis, nanos);
voidsleepOrCry(long timeToWait)
sleep Or Cry
sleepOrCry(timeToWait, null);
voidsleepPeriod(double period)
sleep Period
try {
    long millis = (long) (period * 1000);
    int nanos = (int) ((period * 1000 - millis) * 1000000);
    Thread.sleep(millis, nanos);
} catch (InterruptedException e) {
    throw new RuntimeException(e);
voidsleepQuietly(int millis)
sleep Quietly
try {
    Thread.sleep(millis);
} catch (InterruptedException e) {
    throw new RuntimeException(e);
booleansleepQuietly(long millis)
Invokes Thread.sleep(long), catching any InterruptedException that is thrown.
try {
    Thread.sleep(millis);
} catch (InterruptedException e) {
    return false;
return true;
longsleepQuietly(long millis)
Sleeps for the specified number of milliseconds, catching and ignoring any InterruptedException.
long start = System.currentTimeMillis();
try {
    Thread.sleep(millis);
} catch (InterruptedException ignored) {
return System.currentTimeMillis() - start;