public class TimeUtils
extends java.lang.Object
Constructor and Description |
---|
TimeUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
sleepFor(long period,
java.util.concurrent.TimeUnit timeUnit)
This method is a convenience method for method sleep() of classes Thread or TimeUnit.
|
static void |
sleepFor(TimeInterval timeInterval)
This is an overload for method
sleepFor(long, TimeUnit) which is provided for convenience. |
public static void sleepFor(long period, java.util.concurrent.TimeUnit timeUnit)
InterruptedException
So when this method is used, there is no need to worry about catching InterruptedException
This method has TimeUnit
parameter in addition to time period so it makes it very convenient. So with
this method there is no need to convert the time into milliseconds. Just simply write
sleepFor(10, TimeUnit.SECONDS);
InterruptedException
it interrupts current thread
so, that Thread Interruption mechanism continues to work when this method is usedperiod
- time period to sleeptimeUnit
- TimeUnit
that specifies in which units the time period is measuredpublic static void sleepFor(TimeInterval timeInterval)
sleepFor(long, TimeUnit)
which is provided for convenience.
Method sleepFor(long, TimeUnit)
could be very readable if you use actual values, for example
sleepFor(10, TimeUnit.SECONDS);
TimeInterval
, then
it doesn't make it any more readable to write
TimeUtils.sleepFor(timeInterval.getValue(), timeInterval.getTimeUnit());
timeInterval
- TimeInterval
instance that holds the time period to be waited for