public class ReusableLatch extends Object
This class will use the framework provided to by AbstractQueuedSynchronizer.
AbstractQueuedSynchronizer is the framework for any sort of concurrent synchronization, such as Semaphores, events, etc, based on AtomicIntegers.
This class works just like CountDownLatch, with the difference you can also increase the counter
It could be used for sync points when one process is feeding the latch while another will wait when everything is done. (e.g. waiting IO completions to finish)
On ActiveMQ Artemis we have the requirement of increment and decrement a counter until the user fires a ready event (commit). At that point we just act as a regular countDown.
Note: This latch is reusable. Once it reaches zero, you can call up again, and reuse it on further waits.
For example: prepareTransaction will wait for the current completions, and further adds will be called on the latch. Later on when commit is called you can reuse the same latch.
Constructor and Description |
---|
ReusableLatch() |
ReusableLatch(int count) |
public ReusableLatch()
public ReusableLatch(int count)
public int getCount()
public void setCount(int count)
public void countUp()
public void countDown()
public void countDown(int count)
public void await() throws InterruptedException
InterruptedException
public boolean await(long milliseconds) throws InterruptedException
InterruptedException
public boolean await(long timeWait, TimeUnit timeUnit) throws InterruptedException
InterruptedException
Copyright © 2019 JBoss by Red Hat. All rights reserved.