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
public class SynchronizedStack<T> extends java.lang.ObjectThis is intended as a (mostly) GC-free alternative toStackwhen 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
Fields Modifier and Type Field Description static intDEFAULT_SIZEThe default initial capacity for a new stack.
-
Constructor Summary
Constructors Constructor Description SynchronizedStack()Constructs 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears all objects from the stack.Tpop()Pops an object from the stack.booleanpush(T obj)Pushes an object onto the stack.voidsetLimit(int limit)Sets the maximum number of elements that can be pushed onto this stack.
-
-
-
Field Detail
-
DEFAULT_SIZE
public static final int DEFAULT_SIZE
The default initial capacity for a new stack.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
push
public boolean push(T obj)
Pushes an object onto the stack.- Parameters:
obj- The object to push- Returns:
trueif the object was pushed,falseif the stack is full
-
pop
public T 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.- Parameters:
limit- the maximum size, or -1 for unlimited
-
-