public interface ICountDownLatch extends Instance
java.util.concurrent.CountDownLatch
.
Hazelcast's 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.
Unlike Java's implementation, Hazelcast's ICountDownLatch count can be re-set
after a countdown has finished but not during an active count. This allows the same
proxy instance to be reused.
The Hazelcast member that successfully invokes setCount(int)
becomes
the owner of the countdown and is responsible for staying connected to
the cluster until the count reaches zero. If the owner becomes disconnected prior
to count reaching zero all awaiting threads will be notified. This provides a
safety mechanism in the distributed environment.Instance.InstanceType
Modifier and Type | Method and Description |
---|---|
void |
await()
Causes the current thread to wait until the latch has counted down to
zero or an exception is thrown.
|
boolean |
await(long timeout,
TimeUnit unit)
Causes the current thread to wait until the latch has counted down to
zero, an exception is thrown, or the specified waiting time elapses.
|
void |
countDown()
Decrements the count of the latch, releasing all waiting threads if
the count reaches zero.
|
LocalCountDownLatchStats |
getLocalCountDownLatchStats() |
String |
getName()
Returns the name of this ICountDownLatch instance.
|
boolean |
hasCount()
Returns whether the current count is greater than zero.
|
boolean |
setCount(int count)
Sets the count to the given value if the current count is zero.
|
destroy, getId, getInstanceType
String getName()
void await() throws InstanceDestroyedException, MemberLeftException, InterruptedException
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 four things happen:
countDown()
method;
InstanceDestroyedException
will be thrown.
If the countdown owner becomes disconnected while waiting then
MemberLeftException
will be thrown.
If the current thread:
InterruptedException
is thrown and the current thread's
interrupted status is cleared.InstanceDestroyedException
- if the instance is destroyed while waitingMemberLeftException
- if the countdown owner becomes disconnected while waitingInterruptedException
- if the current thread is interruptedIllegalStateException
- if hazelcast instance is shutdown while waitingboolean await(long timeout, TimeUnit unit) throws InstanceDestroyedException, MemberLeftException, InterruptedException
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 five things happen:
countDown()
method;
If the count reaches zero then the method returns with the
value true
.
InstanceDestroyedException
will be thrown.
If the countdown owner becomes disconnected while waiting then
MemberLeftException
will be thrown.
If the current thread:
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
argumenttrue
if the count reached zero and false
if the waiting time elapsed before the count reached zeroInstanceDestroyedException
- if the instance is destroyed while waitingMemberLeftException
- if the countdown owner becomes disconnected while waitingInterruptedException
- if the current thread is interruptedIllegalStateException
- if hazelcast instance is shutdown while waitingvoid countDown()
null
.
boolean hasCount()
true
if count is greater than zeroboolean setCount(int count)
null
; and
MemberLeftException
.
false
.count
- the number of times countDown()
must be invoked
before threads can pass through await()
true
if the new count was set or false
if the current
count is not zeroIllegalArgumentException
- if count
is negativeLocalCountDownLatchStats getLocalCountDownLatchStats()
Copyright © 2008-2013 Hazelcast, Inc. All Rights Reserved.