Interface KeyedPooledObjectFactory<K,​V>

    • Method Detail

      • makeObject

        PooledObject<V> makeObject​(K key)
                            throws Exception
        Create an instance that can be served by the pool and wrap it in a PooledObject to be managed by the pool.
        Parameters:
        key - the key used when constructing the object
        Returns:
        a PooledObject wrapping 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

        void destroyObject​(K key,
                           PooledObject<V> p)
                    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.

        Parameters:
        key - the key used when selecting the instance
        p - a PooledObject wrapping the instance to be destroyed
        Throws:
        Exception - should be avoided as it may be swallowed by the pool implementation.
        See Also:
        validateObject(K, org.apache.tomcat.dbcp.pool2.PooledObject<V>), KeyedObjectPool.invalidateObject(K, V)
      • validateObject

        boolean validateObject​(K key,
                               PooledObject<V> p)
        Ensures that the instance is safe to be returned by the pool.
        Parameters:
        key - the key used when selecting the object
        p - a PooledObject wrapping the instance to be validated
        Returns:
        false if obj is not valid and should be dropped from the pool, true otherwise.