Class RemoteCountDownLatch
- java.lang.Object
-
- com.oracle.coherence.concurrent.RemoteCountDownLatch
-
- All Implemented Interfaces:
CountDownLatch
public class RemoteCountDownLatch extends Object implements CountDownLatch
A distributed count down latch with the same basic behavior and semantics as the JavaCountDownLatchclass, but uses theNamedCacheto support for synchronization aid that allows one or more threads across multiple cluster members to wait until a set of operations being performed in other threads/members completes.- Since:
- 21.12
- Author:
- as, lh 2021.11.16
-
-
Constructor Summary
Constructors Constructor Description RemoteCountDownLatch(String sName, int count, NamedMap<String,com.oracle.coherence.concurrent.internal.LatchCounter> latches)Constructs aRemoteCountDownLatchinitialized with the given count.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidawait()Causes the current thread to wait until the latch has counted down to zero, unless the thread is interrupted.booleanawait(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.voidcountDown()Decrements the latch count, releasing all waiting threads if the count reaches zero.longgetCount()Returns the current count.longgetInitialCount()Returns the initial count of the latch.protected voidsignalLocalThreads()It is called by the delete event handler to release all waiting threads on the local member if the count reaches zero.StringtoString()Returns a string identifying this latch, as well as its state.
-
-
-
Constructor Detail
-
RemoteCountDownLatch
public RemoteCountDownLatch(String sName, int count, NamedMap<String,com.oracle.coherence.concurrent.internal.LatchCounter> latches)
Constructs aRemoteCountDownLatchinitialized with the given count.- Parameters:
sName- the name of the latchcount- the number of timescountDown()must be invoked before threads can pass throughawait()latches- theNamedMapthat stores this latch's state- Throws:
IllegalArgumentException- ifcountis negative
-
-
Method Detail
-
await
public void await() throws InterruptedExceptionCauses 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,
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
public boolean await(long timeout, TimeUnit unit) throws InterruptedExceptionCauses 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,
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 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()
Decrements the latch count, 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()
Returns the current count.This method is typically used for debugging and testing purposes.
- Specified by:
getCountin interfaceCountDownLatch- Returns:
- the current count
-
getInitialCount
public long getInitialCount()
Returns the initial count of the latch.- Returns:
- the initial count
-
toString
public String toString()
Returns a string identifying this latch, as well as its state.
-
signalLocalThreads
protected void signalLocalThreads()
It is called by the delete event handler to release all waiting threads on the local member if the count reaches zero. If the current count is greater than zero then nothing happens. It passes 0 for releases argument to indicate no countdown on the latch.
-
-