List of utility methods to do Sleep
void | sleepTight(final long millis) Sleep the current thread, ignoring any Exception that might occur. try { Thread.sleep(millis); } catch (Exception e) { |
void | sleepUninterruptedly(long millis) Utility method that sleeps for a given time without interruption. try { Thread.sleep(millis); } catch (InterruptedException ie) { |
void | sleepUninterruptibly(long msecs) Sleeps for a given set of milliseconds, uninterruptibly. long now = System.currentTimeMillis(); long sleepUntil = now + msecs; long remaining; while ((remaining = sleepUntil - now) > 0) { try { Thread.sleep(remaining); } catch (InterruptedException e) { now = System.currentTimeMillis(); |
boolean | sleepUntil(long time) Sleep until a particular time. if (time == 0) { return true; } else if (time < 0) { throw new IllegalArgumentException("negative: " + time); long curTime = System.currentTimeMillis(); for (int i = 0; (i < 100) && (curTime < time); i++) { try { ... |
void | sleepUntil(long timestamp) sleep Until long currentTime; while ((currentTime = System.currentTimeMillis()) < timestamp) { try { Thread.sleep(timestamp - currentTime); } catch (InterruptedException e) { |
int | sleepUpTo(final long millis) Method to add a random delay or if none to yeild to give any waiting threads a chance This helps make test threaded code more random to track synchronized issues try { if (millis > 0) { int realSleep = (int) Math.floor(Math.random() * (millis + 1)); if (realSleep > 0) { Thread.sleep(realSleep); return realSleep; } else { Thread.yield(); ... |
void | sleepWithoutInterrupt(final long msToWait) Sleeps for the given amount of time even if interrupted. long timeMillis = System.currentTimeMillis(); long endTime = timeMillis + msToWait; boolean interrupted = false; while (timeMillis < endTime) { try { Thread.sleep(endTime - timeMillis); } catch (InterruptedException ex) { interrupted = true; ... |
void | sleepWithoutInterruptions(long milliseconds) sleep Without Interruptions try { Thread.sleep(milliseconds); } catch (final InterruptedException e) { throw new IllegalStateException(e); |
void | sleepyMillis(long millis) Sleeps for the given count of milli seconds (1000ms = 1sec). try { Thread.sleep(millis); } catch (InterruptedException e) { |