Class AbstractPoolSet<T>

java.lang.Object
org.jppf.utils.pooling.AbstractPoolSet<T>
Type Parameters:
T - the type of objects in the pool.
All Implemented Interfaces:
ObjectPool<T>

public abstract class AbstractPoolSet<T> extends Object implements ObjectPool<T>
A thread-safe, dynamic object pool backed by a HashMap. 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
    Modifier and Type
    Field
    Description
    protected final Map<T,Void>
    The pool of objects.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract T
    Create a new object for the pool.
    get()
    Get an object from the pool, or create it if the pool is empty.
    boolean
    Determine whether this pool is empty.
    void
    put(T t)
    Release an object into this pool, and make it available.
    int
    Use this method with precaution, as its performance is in O(n).
    Get the number of objects in this pool.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • queue

      protected final Map<T,Void> queue
      The pool of objects.
  • Constructor Details

    • AbstractPoolSet

      public AbstractPoolSet()
  • 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>
      Returns:
      a new Object of the type handled by this pool.
    • create

      protected abstract T create()
      Create a new object for the pool.
      Returns:
      an object that can be returned to the 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>
      Parameters:
      t - the object to release.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ObjectPool
      Determine whether this pool is empty.
      Specified by:
      isEmpty in interface ObjectPool<T>
      Returns:
      true if the pool is empty, false otherwise.
    • 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:
      size in interface ObjectPool<T>
      Returns:
      the size of this pool, or -1 if this operation is not supported.