Java TimeUnit Calculate sleepAndCachedInterruptedException(long sleepFor, TimeUnit unit)

Here you can find the source of sleepAndCachedInterruptedException(long sleepFor, TimeUnit unit)

Description

Sleep and cached InterruptedException.

License

Apache License

Parameter

Parameter Description
millis a parameter

Return

true:normal end, false: Interrupted

Declaration

public final static boolean sleepAndCachedInterruptedException(long sleepFor, TimeUnit unit) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.concurrent.TimeUnit;

public class Main {
    /**/*from ww  w  . ja v a2 s  . c  o m*/
     * Sleep and cached InterruptedException.
     * 
     * @param millis
     * @return true:normal end, false: Interrupted
     */
    public final static boolean sleepAndCachedInterruptedException(long sleepFor, TimeUnit unit) {
        if (sleepFor <= 0) {
            return true;
        }
        try {
            unit.sleep(sleepFor);
            return true;
        } catch (InterruptedException e) {
            // omit
            return false;
        }
    }
}

Related

  1. sleep(long duration, TimeUnit timeUnit)
  2. sleep(long duration, TimeUnit timeUnit)
  3. sleep(long pTime, TimeUnit pTimeUnit)
  4. sleep(TimeUnit timeUnit, long duration)
  5. sleep(TimeUnit unit, long length)
  6. sleepFor(long period, TimeUnit timeUnit)
  7. timeDiff(Calendar end, Calendar begin, TimeUnit timeUnit)
  8. timeDiff(Date date1, Date date2, TimeUnit minutes)
  9. timeSince(final long startNanos, final TimeUnit destUnit)