Enum TimeUnit
- All Implemented Interfaces:
Comparable<TimeUnit>
A unit of time, for timeouts such as
Future.get(long, TimeUnit). Conversions
saturate: a value too large for the target unit becomes Long.MAX_VALUE or
Long.MIN_VALUE rather than overflowing.-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionDays.Hours.Millionths of a second.Thousandths of a second.Minutes.Billionths of a second.Seconds. -
Method Summary
Modifier and TypeMethodDescriptionlongsourceDurationinsourceUnit, converted to this unit.voidsleep(long timeout) Sleeps fortimeoutof this unit, asThread.sleepdoes.voidWaits up totimeoutof this unit forthreadto end, asthread.joindoes.voidWaits onobjfortimeoutof this unit, asobj.waitdoes.longtoDays(long d) dof this unit in days.longtoHours(long d) dof this unit in hours.longtoMicros(long d) dof this unit in microseconds.longtoMillis(long d) dof this unit in milliseconds.longtoMinutes(long d) dof this unit in minutes.longtoNanos(long d) dof this unit in nanoseconds.longtoSeconds(long d) dof this unit in seconds.static TimeUnitReturns the enum constant of this type with the specified name.static TimeUnit[]values()Returns an array containing the constants of this enum type, in the order they are declared.Methods inherited from class Enum
clone, compareTo, equals, getDeclaringClass, getEnumValues, hashCode, name, ordinal, setEnumValues, toString, valueOf
-
Enum Constant Details
-
NANOSECONDS
Billionths of a second. -
MICROSECONDS
Millionths of a second. -
MILLISECONDS
Thousandths of a second. -
SECONDS
Seconds. -
MINUTES
Minutes. -
HOURS
Hours. -
DAYS
Days.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
convert
sourceDurationinsourceUnit, converted to this unit.- Parameters:
sourceDuration- the durationsourceUnit- its unit- Returns:
- the duration in this unit
-
toNanos
public long toNanos(long d) dof this unit in nanoseconds.- Parameters:
d- the duration- Returns:
- the converted duration
-
toMicros
public long toMicros(long d) dof this unit in microseconds.- Parameters:
d- the duration- Returns:
- the converted duration
-
toMillis
public long toMillis(long d) dof this unit in milliseconds.- Parameters:
d- the duration- Returns:
- the converted duration
-
toSeconds
public long toSeconds(long d) dof this unit in seconds.- Parameters:
d- the duration- Returns:
- the converted duration
-
toMinutes
public long toMinutes(long d) dof this unit in minutes.- Parameters:
d- the duration- Returns:
- the converted duration
-
toHours
public long toHours(long d) dof this unit in hours.- Parameters:
d- the duration- Returns:
- the converted duration
-
toDays
public long toDays(long d) dof this unit in days.- Parameters:
d- the duration- Returns:
- the converted duration
-
timedWait
Waits onobjfortimeoutof this unit, asobj.waitdoes.- Parameters:
obj- the monitor, which the caller must holdtimeout- how long to wait- Throws:
InterruptedException- when the thread is interrupted
-
timedJoin
Waits up totimeoutof this unit forthreadto end, asthread.joindoes.- Parameters:
thread- the thread to wait fortimeout- how long to wait- Throws:
InterruptedException- when the waiting thread is interrupted
-
sleep
Sleeps fortimeoutof this unit, asThread.sleepdoes.- Parameters:
timeout- how long to sleep- Throws:
InterruptedException- when the thread is interrupted
-