Java Sleep sleep(long ms)

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

Description

Sleeps the current thread for the specified length of time represented as milliseconds without the need for a try/catch enclosure.

License

Apache License

Parameter

Parameter Description
ms The milliseconds to sleep

Return

Whether or not an InterruptedException was thrown by Thread#sleep(long)

Declaration

public static boolean sleep(long ms) 

Method Source Code

//package com.java2s;
/*/*  ww  w  .  j av  a2s  .co m*/
 * Copyright 2018 ImpactDevelopment
 *
 * Licensed 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 {
    /**
     * Sleeps the current thread for the specified length
     * of time represented as milliseconds without the need
     * for a try/catch enclosure.
     *
     * @see Thread#sleep(long)
     *
     * @param ms The milliseconds to sleep
     * @return Whether or not an {@code InterruptedException} was thrown by {@code Thread#sleep(long)}
     */
    public static boolean sleep(long ms) {
        if (ms <= 0) {
            return true;
        }

        try {
            Thread.sleep(ms);
            return true;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }
}

Related

  1. Sleep(long milliseconds)
  2. sleep(long milliseconds)
  3. sleep(long milliTime)
  4. sleep(long ms)
  5. sleep(long ms)
  6. sleep(long msecs, boolean busy_sleep)
  7. sleep(long msecs, boolean busy_sleep)
  8. sleep(long sleepTime)
  9. sleep(long sleepTime)