Package org.jppf.utils.pooling
Class AbstractObjectPoolQueue<T>
java.lang.Object
org.jppf.utils.pooling.AbstractObjectPoolQueue<T>
- Type Parameters:
T- the type of objects in the pool.
- All Implemented Interfaces:
ObjectPool<T>
- Direct Known Subclasses:
AbstractBoundedObjectPoolQueue,DirectBufferPoolQueue,SynchronizedDirectBufferPool
A thread-safe, dynamic object pool backed by a
LinkedBlockingQueue.
This pool is designed for maximum throughput, thus its size will grow dynamically,
up to maximum concurrent usage.
Subclasses that wish to avoid a size too large for the pool may for instance
introduce a core pool size, and override the put(T) method such that it
doesn't put released object back into the queue if its size > core size.
In this case the size() method might need to be overriden as well, as its
performance in O(n) may be the main bottleneck of the implementation.
- Author:
- Laurent Cohen
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Tcreate()Create a new object for the pool.get()Get an object from the pool, or create it if the pool is empty.booleanisEmpty()Determine whether this pool is empty.voidRelease an object into this pool, and make it available.intsize()Use this method with precaution, as its performance is in O(n).
Get the number of objects in this pool.
-
Field Details
-
queue
The pool of objects.
-
-
Constructor Details
-
AbstractObjectPoolQueue
public AbstractObjectPoolQueue()
-
-
Method Details
-
get
Description copied from interface:ObjectPoolGet an object from the pool, or create it if the pool is empty.- Specified by:
getin interfaceObjectPool<T>- Returns:
- a new Object of the type handled by this pool.
-
createQueue
- Returns:
- the new queue.
-
create
Create a new object for the pool.- Returns:
- an object that can be returned to the pool.
-
put
Description copied from interface:ObjectPoolRelease an object into this pool, and make it available.- Specified by:
putin interfaceObjectPool<T>- Parameters:
t- the object to release.
-
isEmpty
public boolean isEmpty()Description copied from interface:ObjectPoolDetermine whether this pool is empty.- Specified by:
isEmptyin interfaceObjectPool<T>- Returns:
trueif the pool is empty,falseotherwise.
-
size
public int size()Use this method with precaution, as its performance is in O(n).
Get the number of objects in this pool. This is an optional operation, as it may not always be done in constant time.- Specified by:
sizein interfaceObjectPool<T>- Returns:
- the size of this pool, or -1 if this operation is not supported.
-