Java Sleep sleep(final int millis)

Here you can find the source of sleep(final int millis)

Description

Sleeps the current thread, useful to handle interrupted exceptions.

License

Open Source License

Parameter

Parameter Description
millis Number of milliseconds to sleep

Return

False on InterruptedException, true otherwise (implying that we have slept for the desired time duration)

Declaration

public static boolean sleep(final int millis) 

Method Source Code

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

public class Main {
    public static boolean sleep(final double millis) {
        return sleep((int) millis);
    }/*from   www  . jav  a  2  s .co m*/

    /**
     * Sleeps the current thread, useful to handle interrupted exceptions.
     * This method sets the interrupted flag on the current thread, per best practice:
     *  - http://www.yegor256.com/2015/10/20/interrupted-exception.html
     *  - http://stackoverflow.com/questions/3976344/handling-interruptedexception-in-java
     *
     * @param millis Number of milliseconds to sleep
     * @return False on InterruptedException, true otherwise (implying that we have slept for the desired time duration)
     */
    public static boolean sleep(final int millis) {
        try {
            Thread.sleep(millis);
            return true;
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            return false;
        }
    }
}

Related

  1. sleep()
  2. sleep()
  3. sleep(double numSeconds)
  4. sleep(double seconds)
  5. sleep(double secs)
  6. sleep(final int ms)
  7. sleep(final int timeMs)
  8. sleep(final long miliseconds)
  9. sleep(final long millis)