Class Pool<T>

  • Type Parameters:
    T -
    Direct Known Subclasses:
    ConnectionPool

    public abstract class Pool<T>
    extends java.lang.Object
    Generic object pool.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Queue<T> store
      Store of reusable objects.
    • Constructor Summary

      Constructors 
      Constructor Description
      Pool()
      Default constructor.
      Pool​(int initialSize)
      Constructor.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void checkin​(T object)
      Checks in an object into the pool.
      T checkout()
      Checks out an object from the pool.
      void clear()
      Clears the store of reusable objects.
      protected void clear​(T object)
      Clears the given object when it is checked in the pool.
      protected abstract T createObject()
      Creates a new reusable object.
      protected java.util.Queue<T> createStore()
      Creates the store of reusable objects.
      protected java.util.Queue<T> getStore()
      Returns the store containing the reusable objects.
      void preCreate​(int initialSize)
      Pre-creates the initial objects using the createObject() method and check them in the pool using the checkin(Object) method.
      • Methods inherited from class java.lang.Object

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

      • store

        private final java.util.Queue<T> store
        Store of reusable objects.
    • Constructor Detail

      • Pool

        public Pool()
        Default constructor.
      • Pool

        public Pool​(int initialSize)
        Constructor. Pre-creates the minimum number of objects if needed using the preCreate(int) method.
        Parameters:
        initialSize - The initial number of objects in the pool.
    • Method Detail

      • checkin

        public void checkin​(T object)
        Checks in an object into the pool.
        Parameters:
        object - The object to check in.
      • checkout

        public T checkout()
        Checks out an object from the pool. Creates a new one if the pool is empty.
        Returns:
        An object from the pool.
      • clear

        public void clear()
        Clears the store of reusable objects.
      • clear

        protected void clear​(T object)
        Clears the given object when it is checked in the pool. Does nothing by default.
        Parameters:
        object - The object to clear.
      • createObject

        protected abstract T createObject()
        Creates a new reusable object.
        Returns:
        A new reusable object.
      • createStore

        protected java.util.Queue<T> createStore()
        Creates the store of reusable objects.
        Returns:
        The store of reusable objects.
      • getStore

        protected java.util.Queue<T> getStore()
        Returns the store containing the reusable objects.
        Returns:
        The store containing the reusable objects.
      • preCreate

        public void preCreate​(int initialSize)
        Pre-creates the initial objects using the createObject() method and check them in the pool using the checkin(Object) method.
        Parameters:
        initialSize - The initial number of objects.