Java Sleep sleep(long millis)

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

Description

Utility method that causes the current thread to sleep.

License

Apache License

Parameter

Parameter Description
millis the number of milliseconds to wait

Declaration

public static void sleep(long millis) 

Method Source Code

//package com.java2s;
/*//w w w .j  a v  a 2 s .c o m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

public class Main {
    /**
     * Enable debug messages ?
     */
    public static final boolean TRACE = false;

    /**
     * Utility method that causes the current thread to sleep.
     *
     * @param millis the number of milliseconds to wait
     */
    public static void sleep(long millis) {
        long past = System.currentTimeMillis();
        long future = past + millis;
        long now = past;
        if (TRACE) {
            System.err.println("Sleeping for " + millis + "ms");
        }
        while (now < future) {
            try {
                Thread.sleep(future - now);
            } catch (Exception e) {
            }
            now = System.currentTimeMillis();
        }
    }
}

Related

  1. sleep(long duration)
  2. sleep(long interval)
  3. sleep(long l)
  4. sleep(long milli)
  5. sleep(long millions)
  6. sleep(long millis)
  7. sleep(Long millis)
  8. sleep(long millis)
  9. sleep(long millis)