Skip to content

Instantly share code, notes, and snippets.

@fuxingloh
Created January 21, 2020 06:47
Show Gist options
  • Save fuxingloh/3108f4614f0ce1ffcf4c567166812f24 to your computer and use it in GitHub Desktop.
Save fuxingloh/3108f4614f0ce1ffcf4c567166812f24 to your computer and use it in GitHub Desktop.
Thread.sleep with checked InterruptedException wrapped in unchecked.
package dev.fuxing.utils;
import java.time.Duration;
/**
* Created by: Fuxing
* Date: 20/8/18
* Time: 6:43 PM
*/
public final class SleepUtils {
private SleepUtils() { /**/ }
/**
* @param duration duration to sleep
*/
public static void sleep(Duration duration) {
sleep(duration.toMillis());
}
/**
* @param millis to sleep
*/
public static void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment