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)
The function causes the currently executing thread to sleep.
try {
    Thread.sleep(millis);
} catch (InterruptedException e) {
    Thread.currentThread().interrupt();
voidsleep(long millis)
sleep
try {
    Thread.sleep(millis);
} catch (InterruptedException ex) {
    return;
voidsleep(long millis)
sleep
if (millis < 0) {
    throw new IllegalArgumentException();
long start = System.currentTimeMillis();
long elapsed = 0;
do {
    try {
        Thread.sleep(millis - elapsed);
...
voidsleep(long millis)
Puts the current thread to sleep for the specificed number of milliseconds.
try {
    Thread.sleep(millis);
} catch (Exception e) {
    e.printStackTrace();
voidsleep(long millis)
sleep
try {
    Thread.sleep(millis);
} catch (InterruptedException ex) {
    throw new RuntimeException(ex);
voidsleep(long millis)
Sleeps the specified number of milliseconds.
long started = System.currentTimeMillis();
long waited = 0;
while (waited < millis) {
    try {
        Thread.sleep(millis - waited);
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
    waited = System.currentTimeMillis() - started;
voidsleep(long millis)
sleep
long now = System.currentTimeMillis();
long remaining = millis - (System.currentTimeMillis() - now);
while (remaining > 0) {
    try {
        Thread.sleep(remaining, 0);
    } catch (InterruptedException e) {
    remaining = millis - (System.currentTimeMillis() - now);
...
booleansleep(long milliseconds)

Puts the current thread to sleep for the specified number of milliseconds.

boolean interrupted = Thread.interrupted();
if (!interrupted) {
    try {
        Thread.sleep(milliseconds);
    } catch (InterruptedException ex) {
        interrupted = true;
        Thread.interrupted();
return !interrupted;
voidSleep(long milliseconds)
Causes the current thread to sleep for a certain length of time.
Thread.currentThread().sleep(milliseconds);
voidsleep(long milliTime)
This method puts the current thread to sleep for the given time in msec.
long wakeupTime = System.currentTimeMillis() + milliTime;
while (milliTime > 0) {
    try {
        Thread.sleep(milliTime);
        break;
    } catch (InterruptedException e) {
        milliTime = wakeupTime - System.currentTimeMillis();