Java Sleep sleepFor(long millis)

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

Description

Sleeps at least until the specified amount of time has passed, uninterruptibly.

License

Open Source License

Parameter

Parameter Description
millis Amount of milliseconds to sleep

Declaration

public static void sleepFor(long millis) 

Method Source Code

//package com.java2s;
/**/*from   ww  w.j a va2s .c om*/
 * Copyright (C) 2011,2012 Gordon Fraser, Andrea Arcuri and EvoSuite
 * contributors
 *
 * This file is part of EvoSuite.
 *
 * EvoSuite is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * EvoSuite is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Public License for more details.
 *
 * You should have received a copy of the GNU Public License along with
 * EvoSuite. If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Sleeps at least until the specified amount of time has passed, uninterruptibly.
     *
     * @param millis Amount of milliseconds to sleep
     */
    public static void sleepFor(long millis) {
        sleepUntil(System.currentTimeMillis() + millis);
    }

    /**
     * Sleeps at least until the specified time point has passed.
     *
     * (Thread.sleep() does something similar, but can stop sleeping before
     * the specified time point has passed if the thread is interrupted.)
     *
     * @param targetTimeMillis Target time in milliseconds
     */
    public static void sleepUntil(long targetTimeMillis) {
        while (true) {
            long delta = targetTimeMillis - System.currentTimeMillis();

            if (delta <= 0) {
                break;
            }

            try {
                Thread.sleep(delta);
            } catch (InterruptedException e) {
                /* OK */ }
        }
    }
}

Related

  1. sleepDeep(long millis)
  2. sleepExp(int countFailures)
  3. sleepFixed(int milliSecond)
  4. sleepFor(int delay )
  5. sleepFor(int sleepDurationInMilliseconds)
  6. sleepForAuditGranularity()
  7. sleepForever()
  8. sleepForever()
  9. sleepForever()