| public enum java.util.concurrent TimeUnit
|
Java SE 6 |
A TimeUnit is mainly used to inform time-based methods
how a given timing parameter should be interpreted. For example,
the following code will timeout in 50 milliseconds if the lock is not available:
Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ...while this code will timeout in 50 seconds:
Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ...Note however, that there is no guarantee that a particular timeout implementation will be able to notice the passage of time at the same granularity as the given TimeUnit.
| since | 1.5 |
| Enum constants | |
|---|---|
| final public static TimeUnit | NANOSECONDS |
| final public static TimeUnit | MICROSECONDS |
| final public static TimeUnit | MILLISECONDS |
| final public static TimeUnit | SECONDS |
| final public static TimeUnit | MINUTES |
| final public static TimeUnit | HOURS |
| final public static TimeUnit | DAYS |
| Methods | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| public long | convert(long sourceDuration, TimeUnit sourceUnit) Details
Convert the given time duration in the given unit to this
unit. Conversions from finer to coarser granularities
truncate, so lose precision. For example converting
999 milliseconds to seconds results in
0. Conversions from coarser to finer granularities
with arguments that would numerically overflow saturate to
Long.MIN_VALUE if negative or Long.MAX_VALUE
if positive.
For example, to convert 10 minutes to milliseconds, use: TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)
| ||||||||
| public void | sleep(long timeout) throws InterruptedException Details
Performs a Thread.sleep using this unit.
This is a convenience method that converts time arguments into the
form required by the Thread.sleep method.
| ||||||||
| public void | timedJoin(Thread thread, long timeout) throws InterruptedException Details
Performs a timed Thread.join using this time unit.
This is a convenience method that converts time arguments into the
form required by the Thread.join method.
| ||||||||
| public void | timedWait(Object obj, long timeout) throws InterruptedException Details
Performs a timed Object.wait using this time unit.
This is a convenience method that converts timeout arguments
into the form required by the Object.wait method.
For example, you could implement a blocking poll
method (see public synchronized Object poll(long timeout, TimeUnit unit) throws InterruptedException {
while (empty) {
unit.timedWait(this, timeout);
...
}
}
| ||||||||
| public long | toDays(long duration) Details
Equivalent to DAYS.convert(duration, this).
| ||||||||
| public long | toHours(long duration) Details
Equivalent to HOURS.convert(duration, this).
| ||||||||
| public long | toMicros(long duration) Details
Equivalent to MICROSECONDS.convert(duration, this).
| ||||||||
| public long | toMillis(long duration) Details
Equivalent to MILLISECONDS.convert(duration, this).
| ||||||||
| public long | toMinutes(long duration) Details
Equivalent to MINUTES.convert(duration, this).
| ||||||||
| public long | toNanos(long duration) Details
Equivalent to NANOSECONDS.convert(duration, this).
| ||||||||
| public long | toSeconds(long duration) Details
Equivalent to SECONDS.convert(duration, this).
| ||||||||
| public static TimeUnit | valueOf(String name) | ||||||||
| public static TimeUnit[] | values() | ||||||||
| About DocWeb · Bundles · Export · Export All | Top 10 · Statistics · Login |
| About Sun · Contact · Privacy · Terms of Use · Trademarks | Java SE 6 · Copyright © 1994-2009 Sun Microsystems, Inc.All rights reserved. Use is subject to license terms |
![]() |
![]() |
|