@ThreadSafe public class VariableLatch extends Object
CountDownLatch except that it can also increase the count dynamically.| Modifier and Type | Class and Description |
|---|---|
private static class |
VariableLatch.Sync
Synchronization control For CountDownLatch.
|
| Modifier and Type | Field and Description |
|---|---|
private VariableLatch.Sync |
sync |
| Constructor and Description |
|---|
VariableLatch(int count)
Constructs a
CountDownLatch initialized with the given count. |
| Modifier and Type | Method and Description |
|---|---|
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,
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 |
countDown(int count)
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.
|
void |
countUp()
Increments the count of the latch by one.
|
void |
countUp(int count)
Increments the count of the latch by a positive number.
|
static VariableLatch |
create()
Create a new variable latch.
|
static VariableLatch |
create(int initialValue)
Create a new variable latch.
|
long |
getCount()
Returns the current count.
|
String |
toString()
Returns a string identifying this latch, as well as its state.
|
private final VariableLatch.Sync sync
public VariableLatch(int count)
CountDownLatch initialized with the given count.count - the number of times countDown() must be invoked
before threads can pass through await()IllegalArgumentException - if count is negativepublic static VariableLatch create()
public static VariableLatch create(int initialValue)
initialValue - the initial number of latchespublic void await()
throws 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; or
If the current thread:
InterruptedException is thrown and the current thread's interrupted status is cleared.InterruptedException - if the current thread is interrupted
while waitingpublic boolean await(long timeout,
TimeUnit unit)
throws 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:
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 zeroInterruptedException - if the current thread is interrupted
while waitingpublic 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 countDown(int count)
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.
count - the number of counts to decreasepublic void countUp()
public void countUp(int count)
count - the number of counts to increasepublic long getCount()
This method is typically used for debugging and testing purposes.
Copyright © 2020 JBoss by Red Hat. All rights reserved.