|Constructor and Description|
|Modifier and Type||Method and Description|
Create an object, and place it into the pool. addObject() is useful for "pre-loading" a pool with idle objects.
Borrow an object from the pool.
Clears any objects sitting idle in the pool.
Close this pool, and free any resources associated with it.
Return the number of instances currently borrowed from this pool.
Returns an approximation not less than the of the number of idle instances in the pool.
Invalidates an object from the pool.
Returns an instance to the pool after successful validation and passivation.
Used by sub-classes to include the fields defined by the sub-class in the
public T borrowObject() throws java.lang.Exception
PooledObjectFactory.makeObject()method is invoked to create a new instance.
All instances are
validated before being returned by this method. If validation fails or
an exception occurs activating or validating an idle instance, the
failing instance is
destroyed and another instance is retrieved from the pool, validated and
activated. This process continues until either the pool is empty or an
instance passes validation. If the pool is empty on activation or it does
not contain any valid instances, the factory's
method is used to create a new instance. If the created instance either
raises an exception on activation or fails validation,
NoSuchElementException is thrown. Exceptions thrown by
MakeObject are propagated to the caller; but other than
generated by activation, validation or destroy methods are swallowed
java.util.NoSuchElementException- if a valid object cannot be provided
java.lang.IllegalStateException- if invoked on a
java.lang.Exception- if an exception occurs creating a new instance
public void returnObject(T obj) throws java.lang.Exception
obj- instance to return to the pool
java.lang.IllegalStateException- if an attempt is made to return an object to the pool that is in any state other than allocated (i.e. borrowed). Attempting to return an object more than once or attempting to return an object that was never borrowed from the pool will trigger this exception.
java.lang.Exception- if an instance cannot be returned to the pool
public void invalidateObject(T obj) throws java.lang.Exception
obj must have been obtained
ObjectPool.borrowObject() or a related method as defined in an
implementation or sub-interface.
This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid.
public void addObject() throws java.lang.Exception
Before being added to the pool, the newly created instance is
validation fails, the new instance is
generated by the factory
passivate are propagated to the caller. Exceptions
destroying instances are silently swallowed.
public int getNumIdle()
public int getNumActive()
public void clear()
public void close()
clear()to destroy and remove instances in the pool.
public PooledObjectFactory<T> getFactory()
PooledObjectFactoryused by this pool to create and manage object instances.
protected void toStringAppendFields(java.lang.StringBuilder builder)
Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.