Java Sleep sleepExp(int countFailures)

Here you can find the source of sleepExp(int countFailures)

Description

Implements simple exponential sleep based on number of failures (count).

License

Open Source License

Declaration

public final static void sleepExp(int countFailures) 

Method Source Code

//package com.java2s;

public class Main {
    private static final int msMinSleep = 100;
    private static final int msMaxSleep = 60000;

    /**/*from   w w w  .j a  v a2 s.  c  o m*/
     * Implements simple exponential sleep based on number of failures (count).
     */
    public final static void sleepExp(int countFailures) {
        long ms = (long) (msMinSleep * Math.pow(countFailures, 1.5));
        sleepMs(Math.min(ms, msMaxSleep));
    }

    public final static void sleepMs(long ms) {
        if (ms > 0) {
            try {
                Thread.sleep(ms);
            } catch (InterruptedException e) {
                // Thread.currentThread().dumpStack();
            }
        }
    }
}

Related

  1. sleepAtLeast(long milliseconds)
  2. sleepBeforeRetry(int attemptNumber)
  3. sleepButInterruptable(long msecs)
  4. sleepCurrentThread()
  5. sleepDeep(long millis)
  6. sleepFixed(int milliSecond)
  7. sleepFor(int delay )
  8. sleepFor(int sleepDurationInMilliseconds)
  9. sleepFor(long millis)