Package org.apache.tomcat.util.threads
Class LimitLatch
- java.lang.Object
- 
- org.apache.tomcat.util.threads.LimitLatch
 
- 
 public class LimitLatch extends java.lang.ObjectShared latch that allows the latch to be acquired a limited number of times after which all subsequent requests to acquire the latch will be placed in a FIFO queue until one of the shares is returned.
- 
- 
Constructor SummaryConstructors Constructor Description LimitLatch(long limit)Instantiates a LimitLatch object with an initial limit.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description longcountDown()Releases a shared latch, making it available for another thread to use.voidcountUpOrAwait()Acquires a shared latch if one is available or waits for one if no shared latch is current available.longgetCount()Returns the current count for the latchlonggetLimit()Obtain the current limit.java.util.Collection<java.lang.Thread>getQueuedThreads()Provide access to the list of threads waiting to acquire this limited shared latch.booleanhasQueuedThreads()Returnstrueif there is at least one thread waiting to acquire the shared lock, otherwise returnsfalse.booleanreleaseAll()voidreset()Resets the latch and initializes the shared acquisition counter to zero.voidsetLimit(long limit)Sets a new limit.
 
- 
- 
- 
Method Detail- 
getCountpublic long getCount() Returns the current count for the latch- Returns:
- the current count for latch
 
 - 
getLimitpublic long getLimit() Obtain the current limit.- Returns:
- the limit
 
 - 
setLimitpublic void setLimit(long limit) Sets a new limit. If the limit is decreased there may be a period where more shares of the latch are acquired than the limit. In this case no more shares of the latch will be issued until sufficient shares have been returned to reduce the number of acquired shares of the latch to below the new limit. If the limit is increased, threads currently in the queue may not be issued one of the newly available shares until the next request is made for a latch.- Parameters:
- limit- The new limit
 
 - 
countUpOrAwaitpublic void countUpOrAwait() throws java.lang.InterruptedExceptionAcquires a shared latch if one is available or waits for one if no shared latch is current available.- Throws:
- java.lang.InterruptedException- If the current thread is interrupted
 
 - 
countDownpublic long countDown() Releases a shared latch, making it available for another thread to use.- Returns:
- the previous counter value
 
 - 
releaseAllpublic boolean releaseAll() - Returns:
- trueif release was done
 
 - 
resetpublic void reset() Resets the latch and initializes the shared acquisition counter to zero.- See Also:
- releaseAll()
 
 - 
hasQueuedThreadspublic boolean hasQueuedThreads() Returnstrueif there is at least one thread waiting to acquire the shared lock, otherwise returnsfalse.- Returns:
- trueif threads are waiting
 
 - 
getQueuedThreadspublic java.util.Collection<java.lang.Thread> getQueuedThreads() Provide access to the list of threads waiting to acquire this limited shared latch.- Returns:
- a collection of threads
 
 
- 
 
-