Java Sleep for Second sleepSeconds(double secs)

Here you can find the source of sleepSeconds(double secs)

Description

Sleeps the number of seconds.

License

Open Source License

Parameter

Parameter Description
secs Number of second to sleep.

Return

Number of milliseconds actually slept.

Declaration

public static long sleepSeconds(double secs) 

Method Source Code

//package com.java2s;
/**/*w  w  w. j av a  2 s.c om*/
 * ? 2003 Cordys R&D B.V. All rights reserved. The computer program(s) is the proprietary information of Cordys R&D B.V. and
 * provided under the relevant License Agreement containing restrictions on use and disclosure. Use is subject to the License
 * Agreement.
 */

public class Main {
    /**
     * Sleeps the number of seconds.
     * 
     * @param secs Number of second to sleep.
     * @return Number of milliseconds actually slept.
     */
    public static long sleepSeconds(double secs) {
        long start = System.currentTimeMillis();

        try {
            Thread.sleep((long) (1000 * secs));
        } catch (InterruptedException e) {
            throw new IllegalStateException("Sleep was interrupted.", e);
        }

        long end = System.currentTimeMillis();

        return end - start;
    }
}

Related

  1. pauseSeconds(long pauseSeconds)
  2. sleepForSeconds(long seconds)
  3. sleepSecond(double second)
  4. sleepSeconds(long seconds)
  5. sleepSeconds(long seconds)
  6. sleepThreadForOneToSuppliedSecond(Thread t, int seconds)
  7. trySleepSeconds(int seconds)