List of utility methods to do Sleep
void | sleepMillis(int milliseconds) sleep Millis try { Thread.sleep(milliseconds); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Interrupted sleeping", e); |
void | sleepMillis(long millis) Sleep for the specific number of milliseconds try { Thread.sleep(millis); } catch (InterruptedException ex) { |
void | sleepMillis(long millis) sleep Millis try { Thread.sleep(millis); } catch (InterruptedException ignored) { |
void | sleepMilliseconds(long ms) Sleeps for the specified time--in milliseconds. try { Thread.sleep(ms); } catch (Exception e) { |
void | sleepMilliseconds(long ms) sleep Milliseconds try { Thread.sleep(ms); } catch (InterruptedException e) { e.printStackTrace(); |
void | sleepMs(final int millis) sleep Ms try { Thread.sleep(millis); } catch (InterruptedException e) { e.printStackTrace(); |
void | sleepMSInChunks(long ms) Sleeps in chunks of 10ms, to prevent the risk of a GC eating the whole sleeping duration, and not letting program enough duration to make progress. final long chunkMS = 10; while (ms >= chunkMS) { try { Thread.sleep(chunkMS); } catch (InterruptedException e) { throw new RuntimeException(e); ms -= chunkMS; ... |
void | sleepNanos(final long nanoDuration) Sleeps for specified amount of time in nanoseconds. final long end = System.nanoTime() + nanoDuration; long timeLeft = nanoDuration; do { if (timeLeft > SLEEP_PRECISION) { Thread.sleep(1); } else if (timeLeft > SPIN_YIELD_PRECISION) { Thread.yield(); timeLeft = end - System.nanoTime(); } while (timeLeft > 0); |
void | sleepNanos(long nanoseconds) sleep Nanos long startTime = System.nanoTime(); long endTime = startTime + nanoseconds; while (endTime >= System.nanoTime()) { |
void | sleepNoException(int ms) sleep No Exception try { Thread.sleep(ms); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("Sleep was interrupted"); |