|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.atlassian.util.concurrent.BooleanLatch
@ThreadSafe public class BooleanLatch
A 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 Summary | |
---|---|
BooleanLatch()
|
Method Summary | |
---|---|
void |
await()
Causes the current thread to wait until the latch has been released, unless the thread is interrupted. |
boolean |
await(long timeout,
java.util.concurrent.TimeUnit unit)
Causes the current thread to wait until the latch has been released, unless the thread is interrupted, or the specified waiting time elapses. |
void |
release()
Release the latch, releasing at most one waiting thread. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BooleanLatch()
Method Detail |
---|
public void release()
If the current state is released then nothing happens.
public void await() throws java.lang.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.
java.lang.InterruptedException
- if the current thread is interrupted while waitingpublic boolean await(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.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.
timeout
- the maximum time to waitunit
- the time unit of the timeout
argument
true
if the count reached zero and false
if the waiting time elapsed
before the count reached zero
java.lang.InterruptedException
- if the current thread is interrupted while waiting
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |