@ThreadSafe public class BooleanLatch extends Object implements ReusableLatch
BooleanLatch is a reusable latch that
resets after it is released and waited on. It depends on a boolean condition
of being released or not and becomes unreleased when one thread successfully
awaits it. It is useful for rally like release-wait-release coordination, and
as a replacement to waiting on a Condition
(it should be faster as the write thread does not need to acquire a lock in
order to signal.
This latch is suitable for SRSW coordination. MRSW is supported but has the
same semantics as Condition.signal(), that
is to say that Condition.signalAll() is
not supported and if there are multiple waiters then the particular thread
that is released is arbitrary.
| Constructor and Description |
|---|
BooleanLatch() |
| Modifier and Type | Method and Description |
|---|---|
void |
await()
Await for the condition to become true.
|
boolean |
await(long timeout,
TimeUnit unit)
Await for the specified time for the condition to become true.
|
void |
release()
Release the latch, releasing one or more threads that are waiting on it.
|
public final void release()
release in interface ReusableLatchpublic final void await()
throws InterruptedException
If the latch has already been released then this method returns immediately.
If the latch is not released then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happen:
release()
method; or
If the current thread:
InterruptedException is thrown and the current
thread's interrupted status is cleared.await in interface AwaitableInterruptedException - if the current thread is interrupted
while waitingpublic final boolean await(long timeout,
TimeUnit unit)
throws InterruptedException
If the latch has already been released then this method returns immediately with return value true.
If the latch is unreleased then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happen:
release()
method; or
If latch is released by another thread then the method returns with the
value true.
If the current thread:
InterruptedException is thrown and the current thread's
interrupted status is cleared.
If the specified waiting time elapses then the value false is
returned. If the time is less than or equal to zero, the method will not
wait at all.
await in interface Awaitabletimeout - the amount to wait.unit - the unit to wait in.InterruptedExceptionCopyright © 2016 Atlassian. All rights reserved.