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

booleansleep(long time)
Sleep the specified number of milliseconds.
if (time <= 0)
    return true;
try {
    Thread.sleep(time);
    return true;
} catch (Exception ex) {
return false;
...
voidsleep(long timeToSleep)
Sleep and wake on InterruptedException
if (timeToSleep <= 0)
    return;
try {
    Thread.sleep(timeToSleep);
} catch (InterruptedException e) {
voidsleep4Subscription()
sleep Subscription
try {
    Thread.currentThread().sleep(1000l);
} catch (Exception ignore) {
voidsleep_force(long timeToSleep)
Sleep and ignore InterruptedException Goto sleep again if wake 1ms ealier
if (timeToSleep <= 0)
    return;
long target = System.currentTimeMillis() + timeToSleep;
while (true)
    try {
        Thread.sleep(timeToSleep);
        timeToSleep = target - System.currentTimeMillis();
        if (timeToSleep < 2)
...
voidsleepABit(long millis)
sleep A Bit
try {
    Thread.sleep(millis);
} catch (InterruptedException e) {
longsleepABitMore()
sleep A Bit More
long before = System.currentTimeMillis();
Thread.sleep(100);
return System.currentTimeMillis() - before;
voidsleepAfterListItems()
sleep After List Items
try {
    Thread.sleep(2000);
} catch (InterruptedException e1) {
    e1.printStackTrace();
voidsleepAndIgnoreInterrupts(int millis)
Sets the current thread to sleep.
try {
    Thread.sleep(millis);
} catch (InterruptedException e1) {
voidsleepAtLeast(long milliseconds)
Make the current thread sleep at least some time, do not care about the exception.
long in = System.currentTimeMillis(), t = 0;
do {
    sleep(milliseconds - t);
    t = System.currentTimeMillis() - in;
} while (t < milliseconds);
voidsleepAtLeast(long milliseconds)
Sleep for a specified duration in milliseconds.
long endTime = System.currentTimeMillis() + milliseconds;
while (System.currentTimeMillis() <= endTime) {
    try {
        Thread.sleep(milliseconds);
    } catch (InterruptedException e) {