21 |
|
* precision. If you use these frequently, consider statically |
22 |
|
* importing this class. |
23 |
|
* |
24 |
< |
* <p>A <tt>TimeUnit</tt> is mainly used to inform blocking methods which |
25 |
< |
* can timeout, how the timeout parameter should be interpreted. For example, |
26 |
< |
* the following code will timeout in 50 milliseconds if the {@link java.util.concurrent.locks.Lock lock} |
27 |
< |
* is not available: |
24 |
> |
* <p>A <tt>TimeUnit</tt> is mainly used to inform blocking timeout |
25 |
> |
* methods how the timeout parameter should be interpreted. For |
26 |
> |
* example, the following code will timeout in 50 milliseconds if the |
27 |
> |
* {@link java.util.concurrent.locks.Lock lock} is not available: |
28 |
> |
* |
29 |
|
* <pre> Lock lock = ...; |
30 |
|
* if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ... |
31 |
|
* </pre> |
184 |
|
|
185 |
|
/** |
186 |
|
* Perform a timed <tt>Object.wait</tt> using this time unit. |
187 |
< |
* This is a convenience method that converts timeout arguments into the |
188 |
< |
* form required by the <tt>Object.wait</tt> method. |
189 |
< |
* <p>For example, you could implement a blocking <tt>poll</tt> method (see |
190 |
< |
* {@link BlockingQueue#poll BlockingQueue.poll} using: |
187 |
> |
* This is a convenience method that converts timeout arguments |
188 |
> |
* into the form required by the <tt>Object.wait</tt> method. |
189 |
> |
* |
190 |
> |
* <p>For example, you could implement a blocking <tt>poll</tt> |
191 |
> |
* method (see {@link BlockingQueue#poll BlockingQueue.poll} |
192 |
> |
* using: |
193 |
> |
* |
194 |
|
* <pre> public synchronized Object poll(long timeout, TimeUnit unit) throws InterruptedException { |
195 |
|
* while (empty) { |
196 |
|
* unit.timedWait(this, timeout); |
197 |
|
* ... |
198 |
|
* } |
199 |
|
* }</pre> |
200 |
+ |
* |
201 |
|
* @param obj the object to wait on |
202 |
|
* @param timeout the maximum time to wait. |
203 |
|
* @throws InterruptedException if interrupted while waiting. |