Java Thread Pause pause(double seconds)

Here you can find the source of pause(double seconds)

Description

pause

License

Open Source License

Declaration

public static void pause(double seconds) 

Method Source Code

//package com.java2s;
/******************************************************************************************
 * COPYRIGHT:                                                                             *
 * Universitat Politecnica de Valencia 2013                                               *
 * Camino de Vera, s/n                                                                    *
 * 46022 Valencia, Spain                                                                  *
 * www.upv.es                                                                             *
 *                                                                                        * 
 * D I S C L A I M E R:                                                                   *
 * This software has been developed by the Universitat Politecnica de Valencia (UPV)      *
 * in the context of the european funded FITTEST project (contract number ICT257574)      *
 * of which the UPV is the coordinator. As the sole developer of this source code,        *
 * following the signed FITTEST Consortium Agreement, the UPV should decide upon an       *
 * appropriate license under which the source code will be distributed after termination  *
 * of the project. Until this time, this code can be used by the partners of the          *
 * FITTEST project for executing the tasks that are outlined in the Description of Work   *
 * (DoW) that is annexed to the contract with the EU.                                     *
 *                                                                                        * 
 * Although it has already been decided that this code will be distributed under an open  *
 * source license, the exact license has not been decided upon and will be announced      *
 * before the end of the project. Beware of any restrictions regarding the use of this    *
 * work that might arise from the open source license it might fall under! It is the      *
 * UPV's intention to make this work accessible, free of any charge.                      *
 *****************************************************************************************/

public class Main {
    public static void pause(double seconds) {
        if (seconds <= 0)
            return;

        //try {//from  w  w w.j  ava2 s  .  c  om
        //   Thread.sleep(Math.round(seconds * 1000.0));
        //} catch (InterruptedException e) {
        //   throw new RuntimeException(e);
        //}

        // begin by urueda
        long sleepT, waitUntil = System.currentTimeMillis() + Math.round(seconds * 1000.0);
        do {
            sleepT = waitUntil - System.currentTimeMillis();
            if (sleepT > 0) {
                try {
                    Thread.sleep(sleepT);
                } catch (InterruptedException e) {
                }
            }
        } while (sleepT > 0);
        // end by urueda
    }
}

Related

  1. pause (final int msec)
  2. pause()
  3. pause(double seconds)
  4. pause(double timeInSec)
  5. pause(final long time)
  6. pause(int i, String unit)
  7. pause(int millis)