Class LocalCountDownLatch
- All Implemented Interfaces:
CountDownLatch
CountDownLatch
interface, that simply wraps java.util.concurrent.CountDownLatch instance.- Author:
- Aleks Seovic 2021.12.05
-
Method Summary
Modifier and TypeMethodDescriptionvoidawait()Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted.booleanCauses the current thread to wait until the latch has counted down to zero, unless the thread is interrupted, or the specified waiting time elapses.voidDecrements the count of the latch, releasing all waiting threads if the count reaches zero.longgetCount()Returns the current count.toString()Returns a string identifying this latch, as well as its state.
-
Method Details
-
await
Description copied from interface:CountDownLatchCauses 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
CountDownLatch.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,
InterruptedExceptionis thrown and the current thread's interrupted status is cleared.- Specified by:
awaitin interfaceCountDownLatch- Throws:
InterruptedException- if the current thread is interrupted while waiting
- The count reaches zero due to invocations of the
-
await
Description copied from interface:CountDownLatchCauses the current thread to wait until the latch has counted down to zero, unless the thread is 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:
- The count reaches zero due to invocations of the
CountDownLatch.countDown()method; or - Some other thread interrupts the current thread; or
- The specified waiting time elapses.
If the count reaches zero then the method returns with the value
true.If the current thread:
- has its interrupted status set on entry to this method; or
- is interrupted while waiting,
InterruptedExceptionis thrown and the current thread's interrupted status is cleared.If the specified waiting time elapses then the value
falseis returned. If the time is less than or equal to zero, the method will not wait at all.- Specified by:
awaitin interfaceCountDownLatch- Parameters:
timeout- the maximum time to waitunit- the time unit of thetimeoutargument- Returns:
trueif the count reached zero andfalseif the if the waiting time elapsed before the count reached zero- Throws:
InterruptedException- if the current thread is interrupted while waiting
- The count reaches zero due to invocations of the
-
countDown
public void countDown()Description copied from interface:CountDownLatchDecrements 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.
- Specified by:
countDownin interfaceCountDownLatch
-
getCount
public long getCount()Description copied from interface:CountDownLatchReturns the current count.This method is typically used for debugging and testing purposes.
- Specified by:
getCountin interfaceCountDownLatch- Returns:
- the current count
-
toString
Returns a string identifying this latch, as well as its state. The state, in brackets, includes the String"Count ="followed by the current count.
-