1 *java.util.concurrent.TimeUnit* *TimeUnit* A TimeUnit represents time durations
3 public final class TimeUnit
4 extends |java.lang.Enum|
6 |java.util.concurrent.TimeUnit_Description|
7 |java.util.concurrent.TimeUnit_Fields|
8 |java.util.concurrent.TimeUnit_Constructors|
9 |java.util.concurrent.TimeUnit_Methods|
11 ================================================================================
13 *java.util.concurrent.TimeUnit_Fields*
14 |java.util.concurrent.TimeUnit_java.util.concurrent.TimeUnit.MICROSECONDS|
15 |java.util.concurrent.TimeUnit_java.util.concurrent.TimeUnit.MILLISECONDS|
16 |java.util.concurrent.TimeUnit_java.util.concurrent.TimeUnit.NANOSECONDS|
17 |java.util.concurrent.TimeUnit_java.util.concurrent.TimeUnit.SECONDS|
19 *java.util.concurrent.TimeUnit_Methods*
20 |java.util.concurrent.TimeUnit.convert(long,TimeUnit)|Convert the given time du
21 |java.util.concurrent.TimeUnit.sleep(long)|Perform a Thread.sleep using this un
22 |java.util.concurrent.TimeUnit.timedJoin(Thread,long)|Perform a timed Thread.jo
23 |java.util.concurrent.TimeUnit.timedWait(Object,long)|Perform a timed Object.wa
24 |java.util.concurrent.TimeUnit.toMicros(long)|Equivalent to MICROSECONDS.conver
25 |java.util.concurrent.TimeUnit.toMillis(long)|Equivalent to MILLISECONDS.conver
26 |java.util.concurrent.TimeUnit.toNanos(long)|Equivalent to NANOSECONDS.convert(
27 |java.util.concurrent.TimeUnit.toSeconds(long)|Equivalent to SECONDS.convert(du
28 |java.util.concurrent.TimeUnit.valueOf(String)|
29 |java.util.concurrent.TimeUnit.values()|
31 *java.util.concurrent.TimeUnit_Description*
33 A TimeUnit represents time durations at a given unit of granularity and
34 provides utility methods to convert across units, and to perform timing and
35 delay operations in these units. A TimeUnit does not maintain time information,
36 but only helps organize and use time representations that may be maintained
37 separately across various contexts.
39 A TimeUnit is mainly used to inform time-based methods how a given timing
40 parameter should be interpreted. For example, the following code will timeout
41 in 50 milliseconds if the lock(|java.util.concurrent.locks.Lock|) is not
44 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ...
46 while this code will timeout in 50 seconds:
48 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ...
50 Note however, that there is no guarantee that a particular timeout
51 implementation will be able to notice the passage of time at the same
52 granularity as the given TimeUnit.
55 *java.util.concurrent.TimeUnit_java.util.concurrent.TimeUnit.MICROSECONDS*
57 A TimeUnit represents time durations at a given unit of granularity and
58 provides utility methods to convert across units, and to perform timing and
59 delay operations in these units. A TimeUnit does not maintain time information,
60 but only helps organize and use time representations that may be maintained
61 separately across various contexts.
63 A TimeUnit is mainly used to inform time-based methods how a given timing
64 parameter should be interpreted. For example, the following code will timeout
65 in 50 milliseconds if the lock(|java.util.concurrent.locks.Lock|) is not
68 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ...
70 while this code will timeout in 50 seconds:
72 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ...
74 Note however, that there is no guarantee that a particular timeout
75 implementation will be able to notice the passage of time at the same
76 granularity as the given TimeUnit.
79 *java.util.concurrent.TimeUnit_java.util.concurrent.TimeUnit.MILLISECONDS*
81 A TimeUnit represents time durations at a given unit of granularity and
82 provides utility methods to convert across units, and to perform timing and
83 delay operations in these units. A TimeUnit does not maintain time information,
84 but only helps organize and use time representations that may be maintained
85 separately across various contexts.
87 A TimeUnit is mainly used to inform time-based methods how a given timing
88 parameter should be interpreted. For example, the following code will timeout
89 in 50 milliseconds if the lock(|java.util.concurrent.locks.Lock|) is not
92 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ...
94 while this code will timeout in 50 seconds:
96 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ...
98 Note however, that there is no guarantee that a particular timeout
99 implementation will be able to notice the passage of time at the same
100 granularity as the given TimeUnit.
103 *java.util.concurrent.TimeUnit_java.util.concurrent.TimeUnit.NANOSECONDS*
105 A TimeUnit represents time durations at a given unit of granularity and
106 provides utility methods to convert across units, and to perform timing and
107 delay operations in these units. A TimeUnit does not maintain time information,
108 but only helps organize and use time representations that may be maintained
109 separately across various contexts.
111 A TimeUnit is mainly used to inform time-based methods how a given timing
112 parameter should be interpreted. For example, the following code will timeout
113 in 50 milliseconds if the lock(|java.util.concurrent.locks.Lock|) is not
116 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ...
118 while this code will timeout in 50 seconds:
120 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ...
122 Note however, that there is no guarantee that a particular timeout
123 implementation will be able to notice the passage of time at the same
124 granularity as the given TimeUnit.
127 *java.util.concurrent.TimeUnit_java.util.concurrent.TimeUnit.SECONDS*
129 A TimeUnit represents time durations at a given unit of granularity and
130 provides utility methods to convert across units, and to perform timing and
131 delay operations in these units. A TimeUnit does not maintain time information,
132 but only helps organize and use time representations that may be maintained
133 separately across various contexts.
135 A TimeUnit is mainly used to inform time-based methods how a given timing
136 parameter should be interpreted. For example, the following code will timeout
137 in 50 milliseconds if the lock(|java.util.concurrent.locks.Lock|) is not
140 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ...
142 while this code will timeout in 50 seconds:
144 Lock lock = ...; if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ...
146 Note however, that there is no guarantee that a particular timeout
147 implementation will be able to notice the passage of time at the same
148 granularity as the given TimeUnit.
152 *java.util.concurrent.TimeUnit.convert(long,TimeUnit)*
156 java.util.concurrent.TimeUnit unit)
158 Convert the given time duration in the given unit to this unit. Conversions
159 from finer to coarser granularities truncate, so lose precision. For example
160 converting 999 milliseconds to seconds results in 0. Conversions from coarser
161 to finer granularities with arguments that would numerically overflow saturate
162 to Long.MIN_VALUE if negative or Long.MAX_VALUE if positive.
164 duration - the time duration in the given unit
165 unit - the unit of the duration argument
167 Returns: the converted duration in this unit, or Long.MIN_VALUE if conversion would
168 negatively overflow, or Long.MAX_VALUE if it would positively
170 *java.util.concurrent.TimeUnit.sleep(long)*
172 public void sleep(long timeout)
173 throws |java.lang.InterruptedException|
175 Perform a Thread.sleep using this unit. This is a convenience method that
176 converts time arguments into the form required by the Thread.sleep method.
178 timeout - the minimum time to sleep
180 *java.util.concurrent.TimeUnit.timedJoin(Thread,long)*
182 public void timedJoin(
183 java.lang.Thread thread,
185 throws |java.lang.InterruptedException|
187 Perform a timed Thread.join using this time unit. This is a convenience method
188 that converts time arguments into the form required by the Thread.join method.
190 thread - the thread to wait for
191 timeout - the maximum time to wait
193 *java.util.concurrent.TimeUnit.timedWait(Object,long)*
195 public void timedWait(
196 java.lang.Object obj,
198 throws |java.lang.InterruptedException|
200 Perform a timed Object.wait using this time unit. This is a convenience method
201 that converts timeout arguments into the form required by the Object.wait
204 For example, you could implement a blocking poll method (see
205 BlockingQueue.poll(|java.util.concurrent.BlockingQueue|) ) using:
207 public synchronized Object poll(long timeout, TimeUnit unit) throws
208 InterruptedException { while (empty) { unit.timedWait(this, timeout); ... } }
210 obj - the object to wait on
211 timeout - the maximum time to wait.
213 *java.util.concurrent.TimeUnit.toMicros(long)*
215 public long toMicros(long duration)
217 Equivalent to MICROSECONDS.convert(duration, this).
219 duration - the duration
221 Returns: the converted duration, or Long.MIN_VALUE if conversion would negatively
222 overflow, or Long.MAX_VALUE if it would positively overflow.
223 *java.util.concurrent.TimeUnit.toMillis(long)*
225 public long toMillis(long duration)
227 Equivalent to MILLISECONDS.convert(duration, this).
229 duration - the duration
231 Returns: the converted duration, or Long.MIN_VALUE if conversion would negatively
232 overflow, or Long.MAX_VALUE if it would positively overflow.
233 *java.util.concurrent.TimeUnit.toNanos(long)*
235 public long toNanos(long duration)
237 Equivalent to NANOSECONDS.convert(duration, this).
239 duration - the duration
241 Returns: the converted duration, or Long.MIN_VALUE if conversion would negatively
242 overflow, or Long.MAX_VALUE if it would positively overflow.
243 *java.util.concurrent.TimeUnit.toSeconds(long)*
245 public long toSeconds(long duration)
247 Equivalent to SECONDS.convert(duration, this).
249 duration - the duration
251 Returns: the converted duration.
252 *java.util.concurrent.TimeUnit.valueOf(String)*
254 public static |java.util.concurrent.TimeUnit| valueOf(java.lang.String name)
259 *java.util.concurrent.TimeUnit.values()*
261 public static final |java.util.concurrent.TimeUnit| values()