Interface ObjectPool<T>

Type Parameters:
T - Type of element pooled in this pool.
All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
BaseObjectPool, GenericObjectPool, PoolUtils.ErodingObjectPool, PoolUtils.SynchronizedObjectPool, SoftReferenceObjectPool

public interface ObjectPool<T> extends Closeable
A pooling simple interface.

Example of use:

 Object obj = null;

 try {
     obj = pool.borrowObject();
     try {
         //...use the object...
     } catch(Exception e) {
         // invalidate the object
         pool.invalidateObject(obj);
         // do not return the object to the pool twice
         obj = null;
     } finally {
         // make sure the object is returned to the pool
         if(null != obj) {
             pool.returnObject(obj);
        }
     }
 } catch(Exception e) {
       // failed to borrow an object
 }

See BaseObjectPool for a simple base implementation.

Since:
2.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Creates an object using the factory or other implementation dependent mechanism, passivate it, and then place it in the idle object pool.
    default void
    addObjects(int count)
    Calls addObject() count number of times.
    Obtains an instance from this pool.
    void
    Clears any objects sitting idle in the pool, releasing any associated resources (optional operation).
    void
    Closes this pool, and free any resources associated with it.
    int
    Returns the number of instances currently borrowed from this pool.
    int
    Returns the number of instances currently idle in this pool.
    void
    Invalidates an object from the pool.
    void
    Returns an instance to the pool.