public interface ICountDownLatch extends DistributedObject
java.util.concurrent.CountDownLatch. ICountDownLatch is a cluster-wide synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes. There are a few differences compared to the
trySetCount(int)after a countdown has finished but not during an active count. This allows the same latch instance to be reused.
ICountDownLatch under split-brain scenarios should be taken into account when using this
data structure. During a split, each partitioned cluster will either create a brand new and uninitialised (zero'd)
ICountDownLatch or it will continue to use the primary or back-up version. For example
it may be possible for both the back-up and primary to be resident in one cluster partition and for another to
be created as new in another side. In any of these cases the counter in the respective
When the split heals, Hazelcast performs a default largest cluster wins resolution or where clusters sizes are equal a random winner is chosen. This can lead to situations where the is left in an unpredictable state, and a countdown to zero may never be achieved.
If required, when using
ICountDownLatch as an orchestration mechanism you should assess the state of the
orchestration outcome and the associated countdown actors after a split-brain heal has taken place, and take steps to
re-orchestrate if appropriate.
|Modifier and Type||Method and Description|
Causes the current thread to wait until the latch has counted down to zero, or an exception is thrown, or the specified waiting time elapses.
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.
Returns the current count.
Sets the count to the given value if the current count is zero.
boolean await(long timeout, TimeUnit unit) throws InterruptedException
If the current count is zero then this method returns immediately
with the value
If the current count is greater than zero, then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of five things happen:
If the count reaches zero, then the method returns with the
If the current thread:
InterruptedExceptionis thrown and the current thread's interrupted status is cleared.
If the specified waiting time elapses then the value
is returned. If the time is less than or equal to zero, the method
will not wait at all.
timeout- the maximum time to wait
unit- the time unit of the
trueif the count reached zero,
falseif the waiting time elapsed before the count reached zero
InterruptedException- if the current thread is interrupted
IllegalStateException- if the Hazelcast instance is shutdown while waiting
NullPointerException- if unit is null
boolean trySetCount(int count)
Copyright © 2017 Hazelcast, Inc.. All Rights Reserved.