Class Pool<T>

  • Type Parameters:
    T - the type of objects managed by this pool
    All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    ConnectionPool, JedisPool

    public abstract class Pool<T>
    extends java.lang.Object
    implements java.io.Closeable
    Base pool class for Jedis connections. This class provides the foundation for connection pooling using Apache Commons Pool, matching the original Jedis Pool architecture.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.commons.pool2.impl.GenericObjectPool<T> internalPool  
    • Constructor Summary

      Constructors 
      Constructor Description
      Pool()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addObjects​(int count)
      Add objects to the pool to reach the minimum idle count.
      void close()  
      protected void closeInternalPool()
      Close the internal pool.
      long getCreatedCount()
      Get the total number of resources created by this pool.
      long getDestroyedCount()
      Get the total number of resources destroyed by this pool.
      long getMaxBorrowWaitTimeMillis()
      Get the maximum time threads have waited for resources.
      int getMaxTotal()
      Get the maximum total number of resources in the pool.
      long getMeanBorrowWaitTimeMillis()
      Get the mean time threads wait for resources.
      int getNumActive()
      Get the number of active resources in the pool.
      int getNumIdle()
      Get the number of idle resources in the pool.
      int getNumWaiters()
      Get the number of threads waiting for resources.
      T getResource()
      Get a resource from the pool.
      void initPool​(org.apache.commons.pool2.impl.GenericObjectPoolConfig<T> poolConfig, org.apache.commons.pool2.PooledObjectFactory<T> pooledObjectFactory)
      Initialize the pool with configuration and factory.
      void initPool​(org.apache.commons.pool2.PooledObjectFactory<T> pooledObjectFactory)
      Initialize the pool with a factory.
      protected void invalidateObject​(T resource)
      Invalidate a resource in the pool.
      boolean isClosed()
      Check if the pool is closed.
      void returnResource​(T resource)
      Return a resource to the pool (public method following original Jedis pattern).
      protected void returnResourceObject​(T resource)
      Return a resource to the pool.
      • Methods inherited from class java.lang.Object

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

      • internalPool

        protected org.apache.commons.pool2.impl.GenericObjectPool<T> internalPool
    • Constructor Detail

      • Pool

        public Pool()
    • Method Detail

      • initPool

        public void initPool​(org.apache.commons.pool2.PooledObjectFactory<T> pooledObjectFactory)
        Initialize the pool with a factory.
        Parameters:
        pooledObjectFactory - the factory for creating pooled objects
      • initPool

        public void initPool​(org.apache.commons.pool2.impl.GenericObjectPoolConfig<T> poolConfig,
                             org.apache.commons.pool2.PooledObjectFactory<T> pooledObjectFactory)
        Initialize the pool with configuration and factory.
        Parameters:
        poolConfig - the pool configuration
        pooledObjectFactory - the factory for creating pooled objects
      • getResource

        public T getResource()
        Get a resource from the pool.
        Returns:
        a resource from the pool
        Throws:
        JedisException - if unable to get a resource
      • returnResourceObject

        protected void returnResourceObject​(T resource)
        Return a resource to the pool.
        Parameters:
        resource - the resource to return
      • returnResource

        public void returnResource​(T resource)
        Return a resource to the pool (public method following original Jedis pattern).
        Parameters:
        resource - the resource to return
      • invalidateObject

        protected void invalidateObject​(T resource)
        Invalidate a resource in the pool.
        Parameters:
        resource - the resource to invalidate
      • getNumActive

        public int getNumActive()
        Get the number of active resources in the pool.
        Returns:
        number of active resources
      • getNumIdle

        public int getNumIdle()
        Get the number of idle resources in the pool.
        Returns:
        number of idle resources
      • getNumWaiters

        public int getNumWaiters()
        Get the number of threads waiting for resources.
        Returns:
        number of waiting threads
      • getMeanBorrowWaitTimeMillis

        public long getMeanBorrowWaitTimeMillis()
        Get the mean time threads wait for resources.
        Returns:
        mean wait time in milliseconds
      • getMaxBorrowWaitTimeMillis

        public long getMaxBorrowWaitTimeMillis()
        Get the maximum time threads have waited for resources.
        Returns:
        maximum wait time in milliseconds
      • getCreatedCount

        public long getCreatedCount()
        Get the total number of resources created by this pool.
        Returns:
        total created count
      • getDestroyedCount

        public long getDestroyedCount()
        Get the total number of resources destroyed by this pool.
        Returns:
        total destroyed count
      • getMaxTotal

        public int getMaxTotal()
        Get the maximum total number of resources in the pool.
        Returns:
        maximum total resources
      • isClosed

        public boolean isClosed()
        Check if the pool is closed.
        Returns:
        true if closed, false otherwise
      • addObjects

        public void addObjects​(int count)
        Add objects to the pool to reach the minimum idle count.
      • closeInternalPool

        protected void closeInternalPool()
        Close the internal pool.
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable