Code example for TimeUnit

Methods: sleep

0
    private static final Logger log = LoggerFactory.getLogger(SleepUtils.class);
 
    public static final void safeSleep( long time, TimeUnit unit) {
 
        try { 
            unit.sleep(time);
        } catch ( InterruptedException e ) {
            log.error("Interrupted while sleeping", e);
        } 
 
    } 
 
    public static final void waitUntil( long millis, Function<Boolean> waiter ) {
 
        long totalSlept = 0;
 
        while ( totalSlept <= millis && !waiter.apply() ) {
            safeSleep(1, TimeUnit.SECONDS);
            totalSlept += 1000;
        }