Package dev.enola.common.concurrent
Class Threads
java.lang.Object
dev.enola.common.concurrent.Threads
-
Method Summary
-
Method Details
-
sleep
Sleep 😴 for a certain duration.This is a wrapper around
Thread.sleep(Duration)which (correctly) handles itsInterruptedExceptionby (re-)interrupting the current thread, and then re-throwing it as a checked exception. It also checks for negative duration (which the original method just ignores, which could hide bugs), and has an optimizing shortcut for duration 0.See Baeldung's related article, or yegor256.com Blog Post and Google Guava Issue #1219, as well as
Uninterruptibles.sleepUninterruptibly(Duration)(which does something different from this).- Parameters:
duration- Duration to sleep- Throws:
UncheckedInterruptedException- if interruptedIllegalArgumentException- if duration is negative
-