public class Timeout extends Object
reset()
method).Modifier and Type | Field and Description |
---|---|
static Timeout |
IMMEDIATE
Specifies a timeout which is always expired; that is, no period of time at all.
|
static Timeout |
NEVER
Specifies a timeout which never expires; that is, an infinite period of time.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasExpired()
Indicates whether the timeout period has elapsed.
|
static Timeout |
millis(long duration)
Creates a timeout expiring in the specified number of milliseconds from now.
|
long |
remainingTime()
Gets the amount of time remaining before the timeout expires.
|
Timeout |
reset()
Resets the timeout to the full duration with which it was created.
|
static Timeout |
seconds(long duration)
Creates a timeout expiring in the specified number of seconds from now.
|
static Timeout |
timeout(long duration,
TimeUnit unit)
Creates a timeout expiring in the specified duration from now.
|
void |
waitOn(Object object)
Waits on the specified object using the
Object.wait() method, honoring the timeout's expiration time. |
public static final Timeout NEVER
public static final Timeout IMMEDIATE
public static Timeout millis(long duration)
duration
- the length of the timeout, specified in millisecondsIllegalArgumentException
- if the duration is non-positive.public static Timeout timeout(long duration, TimeUnit unit)
duration
- the length of the timeout, in the given unitunit
- the time unitIllegalArgumentException
- if the duration is non-positive.public static Timeout seconds(long duration)
duration
- the length of the timeout, specified in secondsIllegalArgumentException
- if the duration is non-positive.public boolean hasExpired()
public long remainingTime()
0
is returned; if the
timeout can never expire, Long.MAX_VALUE
is returned.public void waitOn(Object object) throws InterruptedException
Object.wait()
method, honoring the timeout's expiration time. If
the timeout has expired, no wait will be performed.
The object's monitor must already be held when invoking this method.
object
- the object on which to invoke Object#wait()
InterruptedException
- if the underlying Object#wait()
is interrupted.IllegalMonitorStateException
- if the object's monitor is not held.public Timeout reset()
Timeout
object in loops without requiring constant creation and destruction of objects.Copyright © 2024 Actian Corporation. All rights reserved.