Package org.openiam.esb.util
Class ResettableCountDownLatch
- java.lang.Object
-
- org.openiam.esb.util.ResettableCountDownLatch
-
public class ResettableCountDownLatch extends Object
- Author:
- zaporozhec thanks for https://stackoverflow.com/questions/6595835/resettable-countdownlatch
-
-
Constructor Summary
Constructors Constructor Description ResettableCountDownLatch(int count)
Constructs aCountDownLatch
initialized with the given count.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
await()
Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted.void
countDown()
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.long
getCount()
Returns the current count.void
reset()
String
toString()
Returns a string identifying this latch, as well as its state.
-
-
-
Constructor Detail
-
ResettableCountDownLatch
public ResettableCountDownLatch(int count) throws IllegalArgumentException
Constructs aCountDownLatch
initialized with the given count.- Parameters:
count
- the number of timescountDown()
must be invoked before threads can pass throughawait()
- Throws:
IllegalArgumentException
- ifcount
is negative
-
-
Method Detail
-
await
public void await() throws InterruptedException
Causes the current thread to wait until the latch has counted down to zero, unless the thread is 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:
- The count reaches zero due to invocations of the
countDown()
method; or - Some other thread interrupts the current thread.
If the current thread:
- has its interrupted status set on entry to this method; or
- is interrupted while waiting,
InterruptedException
is thrown and the current thread's interrupted status is cleared.- Throws:
InterruptedException
- if the current thread is interrupted while waiting
- The count reaches zero due to invocations of the
-
reset
public void reset()
-
countDown
public void countDown()
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.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.
-
getCount
public long getCount()
Returns the current count.This method is typically used for debugging and testing purposes.
- Returns:
- the current count
-
-