Package alluxio.concurrent
Class CountingLatch
- java.lang.Object
-
- alluxio.concurrent.CountingLatch
-
public class CountingLatch extends java.lang.Object
Similar toCountDownLatch
except that the count can either be increased or decreased. A thread can wait until the count reaches 0. Other threads can increase or decrease the count concurrently. When count reaches 0, if there is a thread waiting for state 0, the thread will be waken up, and other threads trying to increase the count are blocked. If there is no thread waiting for state 0, then other threads can keep increasing the count. Methods can be run concurrently from different threads, the paired methods(inc()
anddec()
,await()
andrelease()
) do not need to be called in the same thread. An example usage is to synchronize FileSystemContext reinitialization with the ongoing RPCs. See alluxio.client.fs.FileSystemContextReinitializer for more details.
-
-
Constructor Summary
Constructors Constructor Description CountingLatch()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
await()
Blocked during awaiting the counter to become zero.void
dec()
Decreases the counter.void
inc()
Increases the counter.void
release()
Unblocks threads blocked on callinginc()
.
-
-
-
Method Detail
-
inc
public void inc() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
- when interrupted during being blocked
-
dec
public void dec()
Decreases the counter. Should only be called in pair withinc()
. If counter will go below zero after this call, throwsError
. This method is never blocked.
-
await
public void await()
Blocked during awaiting the counter to become zero. When it returns, all further calls toinc()
are blocked.
-
release
public void release()
-
-