Class SynchronizedQueue<T>
- java.lang.Object
-
- org.apache.tomcat.util.collections.SynchronizedQueue<T>
-
- Type Parameters:
T- The type of object managed by this queue
public class SynchronizedQueue<T> extends java.lang.ObjectThis is intended as a (mostly) GC-free alternative toConcurrentLinkedQueuewhen the requirement is to create an unbounded queue with no requirement to shrink the queue. 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 queue.
-
Constructor Summary
Constructors Constructor Description SynchronizedQueue()Constructs a new SynchronizedQueue with the default initial capacity.SynchronizedQueue(int initialSize)Constructs a new SynchronizedQueue with the specified initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all elements from this queue.booleanoffer(T t)Adds the specified element to the tail of this queue.Tpoll()Retrieves and removes the head of this queue, or returns null if this queue is empty.intsize()Returns the number of elements in this queue.
-
-
-
Field Detail
-
DEFAULT_SIZE
public static final int DEFAULT_SIZE
The default initial capacity for a new queue.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SynchronizedQueue
public SynchronizedQueue()
Constructs a new SynchronizedQueue with the default initial capacity.
-
SynchronizedQueue
public SynchronizedQueue(int initialSize)
Constructs a new SynchronizedQueue with the specified initial capacity.- Parameters:
initialSize- the initial capacity
-
-
Method Detail
-
offer
public boolean offer(T t)
Adds the specified element to the tail of this queue.- Parameters:
t- the element to add- Returns:
- true (as specified by
Queue.offer(E))
-
poll
public T poll()
Retrieves and removes the head of this queue, or returns null if this queue is empty.- Returns:
- the head of this queue, or null if empty
-
size
public int size()
Returns the number of elements in this queue.- Returns:
- the number of elements
-
clear
public void clear()
Removes all elements from this queue.
-
-