Class SynchronizedStack<T>
java.lang.Object
org.apache.tomcat.util.collections.SynchronizedStack<T>
- Type Parameters:
T- The type of object managed by this stack
- Direct Known Subclasses:
AbstractProtocol.RecycledProcessors
This is intended as a (mostly) GC-free alternative to
Stack when the requirement is to create a
pool of re-usable objects with no requirement to shrink the pool. The aim is to provide the bare minimum of required
functionality as quickly as possible with minimum garbage.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default initial capacity for a new stack. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new SynchronizedStack with default size and no limit.SynchronizedStack(int size, int limit) Constructs a new SynchronizedStack with the specified initial size and limit. -
Method Summary
-
Field Details
-
DEFAULT_SIZE
public static final int DEFAULT_SIZEThe default initial capacity for a new stack.- See Also:
-
-
Constructor Details
-
SynchronizedStack
public SynchronizedStack()Constructs a new SynchronizedStack with default size and no limit. -
SynchronizedStack
public SynchronizedStack(int size, int limit) Constructs a new SynchronizedStack with the specified initial size and limit.- Parameters:
size- the initial capacitylimit- the maximum capacity, or -1 for unlimited
-
-
Method Details
-
push
Pushes an object onto the stack.- Parameters:
obj- The object to push- Returns:
trueif the object was pushed,falseif the stack is full
-
pop
Pops an object from the stack.- Returns:
- the object at the top of the stack, or
nullif the stack is empty
-
clear
public void clear()Clears all objects from the stack. -
setLimit
public void setLimit(int limit) Sets the maximum number of elements that can be pushed onto this stack. If the new limit is lower than the current capacity, the stack is shrunk. When the stack already holds more elements than the new limit, the most recently pushed elements are retained and the remaining elements are discarded.- Parameters:
limit- the maximum size, or -1 for unlimited
-