# 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 Object
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

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_SIZE`
The 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

Modifier and Type
Method
Description
`void`
`clear()`
Clears all objects from the stack.
`T`
`pop()`
Pops an object from the stack.
`boolean`
`push(T obj)`
Pushes an object onto the stack.
`void`
`setLimit(int limit)`
Sets the maximum number of elements that can be pushed onto this stack.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_SIZE

public static final int DEFAULT_SIZE
The default initial capacity for a new stack.

See Also:
  - Constant Field Values

## 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 capacity
  `limit` - the maximum capacity, or -1 for unlimited

## Method Details

### push

public boolean push(T obj)
Pushes an object onto the stack.

Parameters:
  `obj` - The object to push
Returns:
  `true` if the object was pushed, `false` if the stack is full

### pop

public T pop()
Pops an object from the stack.

Returns:
  the object at the top of the stack, or `null` if 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