public class Timeout extends Object
| Modifier and Type | Field and Description |
|---|---|
static Timeout |
NONE
既不跟踪也不检测超时的空超时。在不需要超时
的情况下使用它,例如在操作不会阻塞的实现中.
|
| Constructor and Description |
|---|
Timeout() |
| Modifier and Type | Method and Description |
|---|---|
Timeout |
clearDeadline() |
Timeout |
clearTimeout() |
Timeout |
deadline(long duration,
TimeUnit unit) |
long |
deadlineNanoTime() |
Timeout |
deadlineNanoTime(long deadlineNanoTime) |
boolean |
hasDeadline() |
void |
throwIfReached()
Throws an
InterruptedIOException if the deadline has been reached or if the current
thread has been interrupted. |
Timeout |
timeout(long timeout,
TimeUnit unit) |
long |
timeoutNanos() |
void |
waitUntilNotified(Object monitor) |
public static final Timeout NONE
public Timeout timeout(long timeout, TimeUnit unit)
timeout - longunit - TimeUnit
Wait at most timeout time before aborting an operation. Using a
per-operation timeout means that as long as forward progress is being made,
no sequence of operations will fail.
If timeout == 0, operations will run indefinitely. (Operating
system timeouts may still apply.)
public long timeoutNanos()
0 for no timeout.public boolean hasDeadline()
public long deadlineNanoTime()
IllegalStateException - if no deadline is set.public Timeout deadlineNanoTime(long deadlineNanoTime)
deadlineNanoTime - longpublic final Timeout deadline(long duration, TimeUnit unit)
duration - longunit - TimeUnitduration time.public Timeout clearTimeout()
public Timeout clearDeadline()
public void throwIfReached()
throws IOException
InterruptedIOException if the deadline has been reached or if the current
thread has been interrupted. This method doesn't detect timeouts; that should be implemented to
asynchronously abort an in-progress operation.IOException - 抛出异常public final void waitUntilNotified(Object monitor) throws InterruptedIOException
monitor - Waits on monitor until it is notified. Throws InterruptedIOException if either
the thread is interrupted or if this timeout elapses before monitor is notified. The
caller must be synchronized on monitor.InterruptedIOException - 抛出异常Copyright © 2020. All rights reserved.