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(int sleepInSeconds)
sleep
if (sleepInSeconds > 0) {
    try { 
        Thread.sleep(1000 * sleepInSeconds); 
    } catch (InterruptedException e) {
voidsleep(int toSleep)
sleep
try {
    long start = System.currentTimeMillis();
    Thread.sleep(toSleep);
    long now;
    while (start + toSleep > (now = System.currentTimeMillis()))
        Thread.sleep(start + toSleep - now);
} catch (InterruptedException e) {
    e.printStackTrace();
...
voidsleep(Integer seconds)
sleep
if (seconds == null || seconds <= 0 || seconds > 60) {
    return;
try {
    Thread.sleep(1000 * seconds);
} catch (InterruptedException ex) {
    Thread.currentThread().interrupt();
voidsleep(Integer threadWaitInMs)
Sleeps the thread for thread_wait_in_ms milliseconds.
if ((threadWaitInMs != null) && (threadWaitInMs > 0))
    try {
        Thread.sleep(threadWaitInMs);
    } catch (Exception e) {
voidsleep(long duration)
sleep
int count = 0;
while (count < duration) {
    try {
        Thread.sleep(1000);
        count++;
    } catch (InterruptedException e) {
booleansleep(long interval)
Sleeps the given interval of time given in milliseconds.
boolean result = true;
try {
    Thread.sleep(interval);
} catch (InterruptedException ex) {
    result = false;
return result;
voidsleep(long l)
Small Utility to consume the InterruptedException associated wiht Thread.sleep
try {
    Thread.sleep(l);
} catch (final InterruptedException e) {
voidsleep(long milli)
Same as Thread#sleep(long) except Exception is caught and ignored.
try {
    Thread.sleep(milli);
} catch (InterruptedException e) {
    Thread.currentThread().interrupt();
voidsleep(long millions)
sleep
try {
    Thread.currentThread().sleep(millions);
} catch (InterruptedException e) {
    e.printStackTrace();
voidsleep(long millis)
Utility method that causes the current thread to sleep.
long past = System.currentTimeMillis();
long future = past + millis;
long now = past;
if (TRACE) {
    System.err.println("Sleeping for " + millis + "ms");
while (now < future) {
    try {
...