Class Pool<T>

  • Direct Known Subclasses:
    ConnectionPool

    public abstract class Pool<T>
    extends Object
    A pool of items, that is to say, a managed list that keeps valid items on it and can create or destroy them as needed. when pushing and popping off a stack.

    Supremely useful with SQL connections. This does check for validity as a matter of course.

    Created by Jeff Gaynor
    on Mar 12, 2010 at 3:48:20 PM

    • Field Detail

      • maxSize

        protected int maxSize
      • totalCreated

        protected int totalCreated
      • totalDestroyed

        protected int totalDestroyed
      • inUse

        protected int inUse
      • DEEP_DEBUG

        protected boolean DEEP_DEBUG
        Set true if you want to see a ton of low level debugging for this.
      • stack

        protected Queue<T> stack
    • Constructor Detail

      • Pool

        public Pool()
    • Method Detail

      • trace

        protected void trace​(String x)
      • getStack

        public Queue<T> getStack()
      • create

        public abstract T create()
                          throws PoolException
        Create a new, ready-to-use object for the pool
        Returns:
        the object
        Throws:
        PoolException
      • destroy

        public abstract void destroy​(T object)
                              throws PoolException
        Destroy an object that is no longer needed.
        Parameters:
        object - the object
        Throws:
        PoolException
      • isValid

        public boolean isValid​(T object)
                        throws PoolException
        Is this item still good? If not it will be removed from the pool so a new one can be created. Default is to return true.
        Throws:
        PoolException
      • pop

        public T pop()
              throws PoolException
        Pop an object off the stack if there is one, otherwise, create one.
        Returns:
        the object
        Throws:
        PoolException
      • doDestroy

        public void doDestroy​(T item)
                       throws PoolException
        Destroying an item reduces the number of in-use items. Do not call this on an item that hasn't been checked out.
        Parameters:
        item - the item
        Throws:
        PoolException
      • setMaxSize

        public void setMaxSize​(int c)
        Set the maximum number of items.
        Parameters:
        c -
      • getMaxSize

        public int getMaxSize()
        Get the maximum number of items
        Returns:
        capacity
      • push

        public void push​(T object)
                  throws PoolException
        Check an object into the pool. If the pool is at capacity, destroy the object.
        Parameters:
        object - the object
        Throws:
        PoolException