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

public abstract class AbstractBoundedObjectPoolQueue<T> extends AbstractObjectPoolQueue<T>
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 Details

    • size

      protected final AtomicInteger size
      The current size of the pool.
    • maxSize

      protected final int maxSize
      The 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

      public T get()
      Description copied from interface: ObjectPool
      Get an object from the pool, or create it if the pool is empty.
      Specified by:
      get in interface ObjectPool<T>
      Overrides:
      get in class AbstractObjectPoolQueue<T>
      Returns:
      a new Object of the type handled by this pool.
    • put

      public void put(T t)
      Description copied from interface: ObjectPool
      Release an object into this pool, and make it available.
      Specified by:
      put in interface ObjectPool<T>
      Overrides:
      put in class AbstractObjectPoolQueue<T>
      Parameters:
      t - the object to release.
    • size

      public int size()
      Description copied from class: AbstractObjectPoolQueue
      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:
      size in interface ObjectPool<T>
      Overrides:
      size in class AbstractObjectPoolQueue<T>
      Returns:
      the size of this pool, or -1 if this operation is not supported.