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

voidsleepBeforeRetry(int attemptNumber)
Used in case we need to re-submit request to AWS when it throws 'AWS Error Code: ServiceUnavailable, AWS Error Message: Service AmazonSimpleDB is currently unavailable.
long sleepMS;
if (attemptNumber < 5) {
    sleepMS = 100;
} else if (attemptNumber < 10) {
    sleepMS = 1000;
} else if (attemptNumber < 15) {
    sleepMS = 5000;
} else if (attemptNumber < 20) {
...
voidsleepButInterruptable(long msecs)
sleep But Interruptable
Thread.sleep(msecs);
voidsleepCurrentThread()
sleep Current Thread
try {
    Thread.sleep(1000);
} catch (InterruptedException e) {
    Thread.currentThread().interrupt();
voidsleepDeep(long millis)
Sleep, suppressing exceptions
try {
    Thread.sleep(millis);
} catch (InterruptedException e) {
voidsleepExp(int countFailures)
Implements simple exponential sleep based on number of failures (count).
long ms = (long) (msMinSleep * Math.pow(countFailures, 1.5));
sleepMs(Math.min(ms, msMaxSleep));
voidsleepFixed(int milliSecond)
Put the calling thread to sleep.
final long endingTime = System.currentTimeMillis() + milliSecond;
long remainingTime = milliSecond;
while (remainingTime > 0) {
    try {
        Thread.sleep(remainingTime);
    } catch (InterruptedException ignore) {
    remainingTime = endingTime - System.currentTimeMillis();
...
voidsleepFor(int delay )
Sleeps the current thread for the given amount of milliseconds.
int x = 0;
while (x < delay) {
    x += SLEEP_DELAY;
    try {
        Thread.sleep(SLEEP_DELAY);
    } catch (InterruptedException ie) {
voidsleepFor(int sleepDurationInMilliseconds)
Attempts to sleep for a specified period
try {
    Thread.sleep(sleepDurationInMilliseconds);
} catch (InterruptedException e) {
    System.out.println("Error sleeping thread for: " + sleepDurationInMilliseconds);
voidsleepFor(long millis)
Sleeps at least until the specified amount of time has passed, uninterruptibly.
sleepUntil(System.currentTimeMillis() + millis);
voidsleepForAuditGranularity()
For audit, make sure event dates don't have the same millisecond.
Thread.sleep(2);