public final class OneShotLatch extends Object
Constructor and Description |
---|
OneShotLatch() |
Modifier and Type | Method and Description |
---|---|
void |
await()
Waits until
trigger() is called. |
void |
await(long timeout,
TimeUnit timeUnit)
Waits until
trigger() is called. |
void |
awaitQuietly()
|
void |
awaitQuietly(long timeout,
TimeUnit timeUnit)
Calls
await(long, TimeUnit) and transforms any InterruptedException or
TimeoutException into a RuntimeException . |
int |
getWaitersCount() |
boolean |
isTriggered()
Checks if the latch was triggered.
|
void |
reset()
Resets the latch so that
isTriggered() returns false. |
String |
toString() |
void |
trigger()
Fires the latch.
|
public void trigger()
await()
will now return.public void await() throws InterruptedException
trigger()
is called. Once trigger()
has been called
this call will always return immediately.InterruptedException
- Thrown if the thread is interrupted while waiting.public void awaitQuietly()
public void await(long timeout, TimeUnit timeUnit) throws InterruptedException, TimeoutException
trigger()
is called. Once #trigger()
has been called
this call will always return immediately.
If the latch is not triggered within the given timeout, a TimeoutException
will be
thrown after the timeout.
A timeout value of zero means infinite timeout and make this equivalent to await()
.
timeout
- The value of the timeout, a value of zero indicating infinite timeout.timeUnit
- The unit of the timeoutInterruptedException
- Thrown if the thread is interrupted while waiting.TimeoutException
- Thrown, if the latch is not triggered within the timeout time.public void awaitQuietly(long timeout, TimeUnit timeUnit)
await(long, TimeUnit)
and transforms any InterruptedException
or
TimeoutException
into a RuntimeException
.public boolean isTriggered()
public int getWaitersCount()
public void reset()
isTriggered()
returns false.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.