Package org.jppf.utils.pooling
Class AbstractBoundedObjectPoolQueue<T>
java.lang.Object
org.jppf.utils.pooling.AbstractObjectPoolQueue<T>
org.jppf.utils.pooling.AbstractBoundedObjectPoolQueue<T>
- Type Parameters:
T- the type of the elements in the pool.
- All Implemented Interfaces:
ObjectPool<T>
- Direct Known Subclasses:
BoundedByteArrayPool
An extension of
AbstractObjectPoolQueue which specifies a maximum size for the pool.
In this implementation, objects are still created dynamically if the pool is empty, however
the put(T) method does not return an element to the backing queue if the pool size >= max size.
the size() method is also overriden to provide results in constant time insteat of O(n) in
the super class, since it is used frequently when comparing current pool size with the max size.
- Author:
- Laurent Cohen
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intThe pool max size.protected final AtomicIntegerThe current size of the pool.Fields inherited from class org.jppf.utils.pooling.AbstractObjectPoolQueue
queue -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBoundedObjectPoolQueue(int maxSize) Initialize this pool with the specified maximum size. -
Method Summary
Modifier and TypeMethodDescriptionget()Get an object from the pool, or create it if the 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).
Use this method with precaution, as its performance is in O(n).
Get the number of objects in this pool.Methods inherited from class org.jppf.utils.pooling.AbstractObjectPoolQueue
create, createQueue, isEmpty
-
Field Details
-
size
The current size of the pool. -
maxSize
protected final int maxSizeThe pool max size.
-
-
Constructor Details
-
AbstractBoundedObjectPoolQueue
public AbstractBoundedObjectPoolQueue(int maxSize) Initialize this pool with the specified maximum size.- Parameters:
maxSize- the pool max size.
-
-
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>- Overrides:
getin classAbstractObjectPoolQueue<T>- Returns:
- a new Object of the type handled by this pool.
-
put
Description copied from interface:ObjectPoolRelease an object into this pool, and make it available.- Specified by:
putin interfaceObjectPool<T>- Overrides:
putin classAbstractObjectPoolQueue<T>- Parameters:
t- the object to release.
-
size
public int size()Description copied from class:AbstractObjectPoolQueueUse 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>- Overrides:
sizein classAbstractObjectPoolQueue<T>- Returns:
- the size of this pool, or -1 if this operation is not supported.
-