T- the type of objects held in this pool
public class SoftReferenceObjectPool<T> extends BaseObjectPool<T> implements ObjectPool<T>
|Constructor and Description|
to be removed in pool 2.0. Use
because this is a SoftReference pool, prefilled idle obejects may be garbage collected before they are used. To be removed in Pool 2.0.
|Modifier and Type||Method and Description|
Create an object, and place it into the pool.
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.
to be removed in pool 2.0
@Deprecated public SoftReferenceObjectPool()
SoftReferenceObjectPoolwithout a factory.
setFactoryshould be called before any attempts to use the pool are made. Generally speaking you should prefer the
public SoftReferenceObjectPool(PoolableObjectFactory<T> factory)
SoftReferenceObjectPoolwith the specified factory.
factory- object factory to use.
@Deprecated public SoftReferenceObjectPool(PoolableObjectFactory<T> factory, int initSize) throws Exception, IllegalArgumentException
SoftReferenceObjectPoolwith the specified factory and initial idle object count.
public T borrowObject() throws Exception
Borrow an object from the pool. If there are no idle instances available in the pool, the configured
PoolableObjectFactory.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
makeObject method is used
to create a new instance. If the created instance either raises an exception on activation or
NoSuchElementException is thrown. Exceptions thrown by
are propagated to the caller; but other than
exceptions generated by activation, validation or destroy methods are swallowed silently.
NoSuchElementException- if a valid object cannot be provided
IllegalStateException- if invoked on a
Exception- if an exception occurs creating a new instance
public void returnObject(T obj) throws Exception
Returns an instance to the pool after successful validation and passivation. The returning instance is destroyed if any of the following are true:
Exceptions passivating or destroying instances are silently swallowed. Exceptions validating instances are propagated to the client.
public void invalidateObject(T obj) throws Exception
Invalidates an object from the pool.
obj must have been obtained
This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid.
Create an object, and place it into the pool. addObject() is useful for "pre-loading" a pool with idle objects.
Before being added to the pool, the newly created instance is
passivated. If validation
fails, the new instance is
Exceptions generated by the factory
propagated to the caller. Exceptions destroying instances are silently swallowed.
public int getNumIdle()
public int getNumActive()
public void clear()
Close this pool, and free any resources associated with it. Invokes
clear() to destroy and remove instances in the pool.
@Deprecated public void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException
factorythis pool uses to create new instances. Trying to change the
factorywhile there are borrowed objects will throw an
Copyright © 2001-2013 The Apache Software Foundation. All Rights Reserved.