public class ModCountDownLatch extends Object
Constructor and Description |
---|
ModCountDownLatch(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.
|
long |
getCount()
Returns the current count.
|
String |
toString()
Returns a string identifying this latch, as well as its state.
|
void |
updateCount()
Updates the counter of the synch variable dynamically Update only if the counter value is > 0
|
public ModCountDownLatch(int count)
count
- the number of times countDown()
must be invoked before threads can pass through await()
.IllegalArgumentException
- if count is less than zero.public void await() throws InterruptedException
interrupted
.
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 interrupts
the current thread.
If the current thread:
interrupted
while waiting, InterruptedException
is
thrown and the current thread's interrupted status is cleared.InterruptedException
- if the current thread is interrupted while waiting.public boolean await(long timeout, TimeUnit unit) throws InterruptedException
interrupted
, or the specified waiting time elapses.
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 interrupts
the current thread; or If the count reaches zero then the method returns with the value true.
If the current thread:
interrupted
while waiting, 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.InterruptedException
- if the current thread is interrupted while waiting.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 updateCount()
public long getCount()
This method is typically used for debugging and testing purposes.
Copyright © 2015 Rice University - Department of Computer Science. All rights reserved.