Interface RCountDownLatch
-
- All Superinterfaces:
RCountDownLatchAsync
,RObject
,RObjectAsync
- All Known Implementing Classes:
RedissonCountDownLatch
public interface RCountDownLatch extends RObject, RCountDownLatchAsync
Distributed implementation ofCountDownLatch
It has an advantage overCountDownLatch
-- count can be set viatrySetCount(long)
method.- Author:
- Nikita Koksharov
-
-
Method Summary
All Methods Instance Methods Abstract 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.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.boolean
trySetCount(long count)
Sets new count value only if previous count already has reached zero or is not set at all.-
Methods inherited from interface org.redisson.api.RCountDownLatchAsync
countDownAsync, getCountAsync, trySetCountAsync
-
Methods inherited from interface org.redisson.api.RObject
copy, delete, dump, getCodec, getName, isExists, migrate, move, rename, renamenx, restore, restore, restoreAndReplace, restoreAndReplace, sizeInMemory, touch, unlink
-
Methods inherited from interface org.redisson.api.RObjectAsync
copyAsync, deleteAsync, dumpAsync, isExistsAsync, migrateAsync, moveAsync, renameAsync, renamenxAsync, restoreAndReplaceAsync, restoreAndReplaceAsync, restoreAsync, restoreAsync, sizeInMemoryAsync, touchAsync, unlinkAsync
-
-
-
-
Method Detail
-
await
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
-
await
boolean await(long timeout, TimeUnit unit) throws InterruptedException
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.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
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,
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.- Parameters:
timeout
- the maximum time to waitunit
- the time unit of thetimeout
argument- Returns:
true
if the count reached zero andfalse
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
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
long getCount()
Returns the current count.This method is typically used for debugging and testing purposes.
- Returns:
- the current count
-
trySetCount
boolean trySetCount(long count)
Sets new count value only if previous count already has reached zero or is not set at all.- Parameters:
count
- - number of timescountDown()
must be invoked before threads can pass throughawait()
- Returns:
true
if new count settedfalse
if previous count has not reached zero
-
-