Java Sleep sleepFixed(int milliSecond)

Here you can find the source of sleepFixed(int milliSecond)

Description

Put the calling thread to sleep.

License

Open Source License

Parameter

Parameter Description
milliSecond milliSecond time to sleep in millisecond

Declaration

public static void sleepFixed(int milliSecond) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*www  . j a  va  2 s  .c  o m*/
     * Put the calling thread to sleep.
     * Note, this thread does not throw interrupted exception,
     * and will not return until the thread has slept for provided time.
     *
     * @param milliSecond milliSecond time to sleep in millisecond
     */
    public static void sleepFixed(int milliSecond) {
        final long endingTime = System.currentTimeMillis() + milliSecond;
        long remainingTime = milliSecond;
        while (remainingTime > 0) {
            try {
                Thread.sleep(remainingTime);
            } catch (InterruptedException ignore) {
            }
            remainingTime = endingTime - System.currentTimeMillis();
        }
    }

    /**
     * Put the calling thread to sleep.
     * Note, this thread does not throw interrupted exception,
     * but may return prematurely as a result of one.
     *
     * @param milliSecond time to sleep in millisecond
     */
    public static void sleep(int milliSecond) {
        try {
            Thread.sleep(milliSecond);
        } catch (InterruptedException ignore) {
        }
    }
}

Related

  1. sleepBeforeRetry(int attemptNumber)
  2. sleepButInterruptable(long msecs)
  3. sleepCurrentThread()
  4. sleepDeep(long millis)
  5. sleepExp(int countFailures)
  6. sleepFor(int delay )
  7. sleepFor(int sleepDurationInMilliseconds)
  8. sleepFor(long millis)
  9. sleepForAuditGranularity()