|
Apache Tomcat 7.0.8 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.tomcat.util.threads.CounterLatch
public class CounterLatch
Simple counter latch that allows code to keep an up and down counter, and waits while the latch holds a certain wait value.
and threads using the latch to wait if the count has reached a certain value.
The counter latch can be used to keep track of an atomic counter, since the operations countDown()
and countUp()
are atomic.
When the latch reaches the wait value, threads will block. The counter latch can hence act like a
count down latch or a count up latch, while letting you keep track of the counter as well.
This counter latch works opposite as the java.util.concurrent.CountDownLatch, since the CounterLatch only blocks on a single value and releases the threads on all other values.
Constructor Summary | |
---|---|
CounterLatch(long initial,
long waitValue)
Instantiates a CounterLatch object with an initial value and a wait value. |
Method Summary | |
---|---|
void |
await()
Causes the calling thread to wait if the counter holds the waitValue. |
boolean |
await(long timeout,
TimeUnit unit)
Causes the calling thread to wait if the counter holds the waitValue. |
boolean |
compareAndSet(long expect,
long update)
Performs an atomic update of the counter If the operation is successful and {@code expect==waitValue && expect! |
long |
countDown()
Decrements the counter |
long |
countUp()
Increments the counter |
long |
getCount()
Returns the current counter value |
Collection<Thread> |
getQueuedThreads()
Returns a collection of the blocked threads |
boolean |
hasQueuedThreads()
returns true if there are threads blocked by this latch |
boolean |
releaseAll()
releases all waiting threads. |
void |
reset(long value)
Resets the latch and initializes the counter with the new value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CounterLatch(long initial, long waitValue)
initial
- - initial value of the counterwaitValue
- - when the counter holds this value,
threads calling await()
or await(long, TimeUnit)
will wait until the counter changes value or until they are interrupted.Method Detail |
---|
public void await() throws InterruptedException
InterruptedException
public boolean await(long timeout, TimeUnit unit) throws InterruptedException
InterruptedException
public long countUp()
public long countDown()
public long getCount()
public boolean compareAndSet(long expect, long update)
expect==waitValue && expect!=update
waiting threads will be released.
expect
- - the expected counter valueupdate
- - the new counter value
true
if successful, false
if the
current value wasn't as expectedpublic boolean hasQueuedThreads()
public Collection<Thread> getQueuedThreads()
public boolean releaseAll()
waitValue
until reset(long)
has been called.
true
if this release of shared mode may permit a
waiting acquire (shared or exclusive) to succeed; and
false
otherwisepublic void reset(long value)
value
- the new counter valuereleaseAll()
|
Apache Tomcat 7.0.8 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |