public final class ResizeableCountDownLatch
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
ResizeableCountDownLatch.Sync
Synchronization control For CountDownLatch.
|
Modifier and Type | Field and Description |
---|---|
private ResizeableCountDownLatch.Sync |
sync |
Constructor and Description |
---|
ResizeableCountDownLatch(int count)
Constructs a
CountDownLatch initialized with the given count. |
Modifier and Type | Method and Description |
---|---|
boolean |
attemptToCountDownAndAwait(long timeout)
Attempts to atomically count down the latch and await release with a timeout.
|
void |
await()
Causes the current thread to wait until the latch has counted down to
zero, unless the thread is interrupted.
|
boolean |
await(long timeout,
java.util.concurrent.TimeUnit unit)
Causes the current thread to wait until the latch has counted down to
zero, unless the thread is interrupted,
or the specified waiting time elapses.
|
void |
countDown()
Decrements the count of the latch, releasing all waiting threads if
the count reaches zero.
|
void |
decreaseCount() |
long |
getCount()
Returns the current count.
|
void |
increaseCount() |
boolean |
isReleasedFlag() |
java.lang.String |
toString()
Returns a string identifying this latch, as well as its state.
|
private final ResizeableCountDownLatch.Sync sync
public ResizeableCountDownLatch(int count)
CountDownLatch
initialized with the given count.count
- the number of times countDown()
must be invoked
before threads can pass through await()
java.lang.IllegalArgumentException
- if count
is negativepublic void await() throws java.lang.InterruptedException
If the current count is zero then this method returns immediately.
If the current count is greater than zero then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happen:
countDown()
method; orIf the current thread:
then 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 current count is zero then this method returns immediately
with the value true
.
If the current count is greater than zero then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happen:
countDown()
method; or
If the count reaches zero then the method returns with the
value true
.
If the current thread:
then 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
argumenttrue
if the count reached zero and false
if the waiting time elapsed before the count reached zerojava.lang.InterruptedException
- if the current thread is interrupted
while waitingpublic boolean attemptToCountDownAndAwait(long timeout) throws java.lang.InterruptedException
timeout
- The time in nanoseconds to awaitjava.lang.InterruptedException
- If the thread gets interrupted while waiting for the releasepublic boolean isReleasedFlag()
public void countDown()
If the current count is greater than zero then it is decremented. If the new count is zero then all waiting threads are re-enabled for thread scheduling purposes.
If the current count equals zero then nothing happens.
public void increaseCount()
public void decreaseCount()
public long getCount()
This method is typically used for debugging and testing purposes.
public java.lang.String toString()
"Count ="
followed by the current count.toString
in class java.lang.Object