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

voidsleep(long millis)
sleep
long sleepStartedAt = System.currentTimeMillis();
try {
    Thread.sleep(millis);
} catch (InterruptedException exception) {
    long sleepInterruptedAt = System.currentTimeMillis();
    long remainingSleepTime = millis - (sleepInterruptedAt - sleepStartedAt);
    sleep(remainingSleepTime);
booleansleep(Long millis)
sleep
if (millis == null || millis <= 0) {
    return true;
try {
    Thread.sleep(millis);
} catch (InterruptedException e) {
    return false;
return true;
voidsleep(long millis)
sleep
if (millis <= 0) {
    if (millis < 0) {
        throw new IllegalArgumentException("" + millis);
    return;
long end = System.currentTimeMillis() + millis;
do {
...
voidsleep(long millis)
sleep
long start;
long end;
long remaining = millis;
do {
    start = System.nanoTime();
    try {
        Thread.sleep(remaining);
        remaining = 0;
...
voidsleep(long millis)
Sleep thread without exception.
try {
    Thread.sleep(millis);
} catch (Throwable e) {
    e.printStackTrace();
voidsleep(long millis)
Sleep and catch the interrupted exception.
try {
    Thread.sleep(millis);
} catch (InterruptedException e) {
voidsleep(long millis)
sleep
try {
    Thread.sleep(millis);
} catch (InterruptedException interruptedException) {
    throw new RuntimeException("Unable to sleep for " + millis + " millis.", interruptedException);
booleansleep(long millis)
Sleep without throwing an exception.
try {
    Thread.sleep(millis);
    return true;
} catch (InterruptedException e) {
    return false;
voidsleep(long millis)
Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
try {
    Thread.sleep(millis);
} catch (InterruptedException e) {
voidsleep(long millis)
sleep
try {
    Thread.sleep(millis);
} catch (Throwable ignored) {