Java Sleep sleepNoException(int ms)

Here you can find the source of sleepNoException(int ms)

Description

sleep No Exception

License

Open Source License

Declaration

public static void sleepNoException(int ms) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void sleepNoException(int ms) {
        try {//w w  w  .j  a va2 s . c om
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException("Sleep was interrupted");
        }
    }

    public static void sleepNoException(int min, int max) {
        int ms = random(min, max);
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException("Sleep was interrupted");
        }
    }

    public static int random(int min, int max) {
        return (int) (min + (Math.random() * max));
    }

    public static double random(double min, double max) {
        return (min + (Math.random() * max));
    }

    public static long random(long min, long max) {
        return (min + ((long) Math.random() * max));
    }
}

Related

  1. sleepMilliseconds(long ms)
  2. sleepMs(final int millis)
  3. sleepMSInChunks(long ms)
  4. sleepNanos(final long nanoDuration)
  5. sleepNanos(long nanoseconds)
  6. sleepNoShit(long nanos)
  7. sleepNotException(long millis)
  8. sleepNoThrow(long timeoutMs)
  9. sleepNs(int ns)