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 ms)
sleep
Object sleep = new Object();
try {
    synchronized (sleep) {
        sleep.wait(ms);
} catch (Exception e) {
    e.printStackTrace();
voidsleep(long ms)
Sleep for a guaranteed number of milliseconds unless interrupted.
long finishAt = System.currentTimeMillis() + ms;
long remaining = ms;
do {
    Thread.sleep(remaining);
    remaining = finishAt - System.currentTimeMillis();
} while (remaining > 0);
booleansleep(long ms)
Sleeps the current thread for the specified length of time represented as milliseconds without the need for a try/catch enclosure.
if (ms <= 0) {
    return true;
try {
    Thread.sleep(ms);
    return true;
} catch (InterruptedException e) {
    e.printStackTrace();
...
voidsleep(long msecs, boolean busy_sleep)
On most UNIX systems, the minimum sleep time is 10-20ms.
if (Thread.interrupted())
    throw new InterruptedException(); 
if (!busy_sleep) {
    sleep(msecs);
    return;
long start = System.currentTimeMillis();
long stop = start + msecs;
...
voidsleep(long msecs, boolean busy_sleep)
On most UNIX systems, the minimum sleep time is 10-20ms.
if (!busy_sleep) {
    sleep(msecs);
    return;
long start = System.currentTimeMillis();
long stop = start + msecs;
while (stop > start) {
    start = System.currentTimeMillis();
...
booleansleep(long sleepTime)
sleep
try {
    Thread.sleep(sleepTime);
    return true;
} catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    return false;
voidsleep(long sleepTime)
Puts the current thread to sleep for the specified amount of time.
Thread currentThread = Thread.currentThread();
try {
    Thread.sleep(sleepTime);
} catch (InterruptedException e) {
    e.printStackTrace();
    currentThread.interrupt();
voidsleep(long time)
sleep
try {
    Thread.sleep(time);
} catch (InterruptedException e) {
    e.printStackTrace();
voidsleep(long time)
Since sleeps are sometimes necessary, this makes an easy way to ignore InterruptedException's.
try {
    Thread.sleep(time);
} catch (InterruptedException e) {
    Thread.currentThread().interrupt();
voidsleep(long time)
Pauses for a given number of milliseconds
try {
    Thread.sleep(time);
} catch (InterruptedException e) {