Java Milliseconds ensureSleepMillis(long millis)

Here you can find the source of ensureSleepMillis(long millis)

Description

Ensures the current thread sleeps at least the given milliseconds before returning from this method.

License

Apache License

Declaration

public static void ensureSleepMillis(long millis) throws InterruptedException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  w  w w  .  j a  v  a 2  s .c  o m*/
     * Ensures the current thread sleeps at least the given milliseconds before
     * returning from this method.
     */
    public static void ensureSleepMillis(long millis) throws InterruptedException {
        if (millis < 1)
            return;
        long now = System.currentTimeMillis();
        final long targetTime = now + millis;

        do {
            Thread.sleep(millis);
            millis = targetTime - System.currentTimeMillis();
        } while (millis > 0);
    }
}

Related

  1. diffTimeInMillis(long start, long end)
  2. durationInMillis(long startNano)
  3. elapsedMillis(long milliseconds)
  4. elapsedMillis(long startTime)
  5. elapsedMillis(long t0nanos, long t1nanos)
  6. expensiveMethodTakingMillis(final int millis)
  7. filetimeToMillis(long filetime)
  8. formatDateMillis(long millis)
  9. FormatDateTime(Calendar p_date, String p_seperator, boolean p_showMilliseconds)