Class PoolUtils.SynchronizedKeyedPoolableObjectFactory<K,V>

java.lang.Object
org.apache.commons.pool.PoolUtils.SynchronizedKeyedPoolableObjectFactory<K,V>
All Implemented Interfaces:
KeyedPoolableObjectFactory<K,V>
Enclosing class:
PoolUtils

private static class PoolUtils.SynchronizedKeyedPoolableObjectFactory<K,V> extends Object implements KeyedPoolableObjectFactory<K,V>
A fully synchronized KeyedPoolableObjectFactory that wraps a KeyedPoolableObjectFactory and synchronizes access to the wrapped factory methods.

Note: This should not be used on pool implementations that already provide proper synchronization such as the pools provided in the Commons Pool library.

  • Field Details

  • Constructor Details

  • Method Details

    • makeObject

      public V makeObject(K key) throws Exception
      Create an instance that can be served by the pool.
      Specified by:
      makeObject in interface KeyedPoolableObjectFactory<K,V>
      Parameters:
      key - the key used when constructing the object
      Returns:
      an instance that can be served by the pool.
      Throws:
      Exception - if there is a problem creating a new instance, this will be propagated to the code requesting an object.
    • destroyObject

      public void destroyObject(K key, V obj) throws Exception
      Destroy an instance no longer needed by the pool.

      It is important for implementations of this method to be aware that there is no guarantee about what state obj will be in and the implementation should be prepared to handle unexpected errors.

      Also, an implementation must take in to consideration that instances lost to the garbage collector may never be destroyed.

      Specified by:
      destroyObject in interface KeyedPoolableObjectFactory<K,V>
      Parameters:
      key - the key used when selecting the instance
      obj - the instance to be destroyed
      Throws:
      Exception - should be avoided as it may be swallowed by the pool implementation.
      See Also:
    • validateObject

      public boolean validateObject(K key, V obj)
      Ensures that the instance is safe to be returned by the pool. Returns false if obj should be destroyed.
      Specified by:
      validateObject in interface KeyedPoolableObjectFactory<K,V>
      Parameters:
      key - the key used when selecting the object
      obj - the instance to be validated
      Returns:
      false if obj is not valid and should be dropped from the pool, true otherwise.
    • activateObject

      public void activateObject(K key, V obj) throws Exception
      Reinitialize an instance to be returned by the pool.
      Specified by:
      activateObject in interface KeyedPoolableObjectFactory<K,V>
      Parameters:
      key - the key used when selecting the object
      obj - the instance to be activated
      Throws:
      Exception - if there is a problem activating obj, this exception may be swallowed by the pool.
      See Also:
    • passivateObject

      public void passivateObject(K key, V obj) throws Exception
      Uninitialize an instance to be returned to the idle object pool.
      Specified by:
      passivateObject in interface KeyedPoolableObjectFactory<K,V>
      Parameters:
      key - the key used when selecting the object
      obj - the instance to be passivated
      Throws:
      Exception - if there is a problem passivating obj, this exception may be swallowed by the pool.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object