public class CountingLatch extends Object
CountDownLatch
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()
and
dec()
, await()
and release()
) 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 and Description |
---|
CountingLatch() |
Modifier and Type | Method and 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 calling
inc() . |
public void inc() throws InterruptedException
InterruptedException
- when interrupted during being blockedpublic void dec()
public void await()
inc()
are blocked.public void release()
Copyright © 2023. All Rights Reserved.