|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.pool2.BaseObjectPool<T>
org.apache.commons.pool2.impl.SoftReferenceObjectPool<T>
T - Type of element pooled in this pool.public class SoftReferenceObjectPool<T>
A SoftReference based ObjectPool.
This class is intended to be thread-safe.
| Constructor Summary | |
|---|---|
SoftReferenceObjectPool(PooledObjectFactory<T> factory)
Create a SoftReferenceObjectPool with the specified factory. |
|
| Method Summary | |
|---|---|
void |
addObject()
Create an object, and place it into the pool. |
T |
borrowObject()
Borrow an object from the pool. |
void |
clear()
Clears any objects sitting idle in the pool. |
void |
close()
Close this pool, and free any resources associated with it. |
PooledObjectFactory<T> |
getFactory()
Returns the PooledObjectFactory used by this pool to create and
manage object instances. |
int |
getNumActive()
Return the number of instances currently borrowed from this pool. |
int |
getNumIdle()
Returns an approximation not less than the of the number of idle instances in the pool. |
void |
invalidateObject(T obj)
Invalidates an object from the pool. |
void |
returnObject(T obj)
Returns an instance to the pool after successful validation and passivation. |
| Methods inherited from class org.apache.commons.pool2.BaseObjectPool |
|---|
assertOpen, isClosed |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SoftReferenceObjectPool(PooledObjectFactory<T> factory)
SoftReferenceObjectPool with the specified factory.
factory - object factory to use.| Method Detail |
|---|
public T borrowObject()
throws Exception
PooledObjectFactory.makeObject() method is invoked to create a
new instance.
All instances are activated
and 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 fails validation,
NoSuchElementException is thrown. Exceptions thrown by
MakeObject are propagated to the caller; but other than
ThreadDeath or VirtualMachineError, exceptions
generated by activation, validation or destroy methods are swallowed
silently.
borrowObject in interface ObjectPool<T>borrowObject in class BaseObjectPool<T>NoSuchElementException - if a valid object cannot be provided
IllegalStateException - if invoked on a closed pool
Exception - if an exception occurs creating a new instance
public void returnObject(T obj)
throws Exception
validation fails
passivation
throws an exception
returnObject in interface ObjectPool<T>returnObject in class BaseObjectPool<T>obj - instance to return to the pool
Exception
public void invalidateObject(T obj)
throws Exception
By contract, obj must have been obtained
using borrowObject.
This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid.
invalidateObject in interface ObjectPool<T>invalidateObject in class BaseObjectPool<T>obj - a borrowed instance to be disposed.
Exception
public void addObject()
throws Exception
Before being added to the pool, the newly created instance is
validated and
passivated. If
validation fails, the new instance is
destroyed. Exceptions
generated by the factory makeObject or
passivate are propagated to the caller. Exceptions
destroying instances are silently swallowed.
addObject in interface ObjectPool<T>addObject in class BaseObjectPool<T>IllegalStateException - if invoked on a closed pool
Exception - when the factory has a problem creating
or passivating an object.public int getNumIdle()
getNumIdle in interface ObjectPool<T>getNumIdle in class BaseObjectPool<T>public int getNumActive()
getNumActive in interface ObjectPool<T>getNumActive in class BaseObjectPool<T>public void clear()
clear in interface ObjectPool<T>clear in class BaseObjectPool<T>public void close()
clear() to destroy and remove instances in the pool.
Calling addObject() or borrowObject() after invoking this
method on a pool will cause them to throw an
IllegalStateException.
close in interface ObjectPool<T>close in class BaseObjectPool<T>public PooledObjectFactory<T> getFactory()
PooledObjectFactory used by this pool to create and
manage object instances.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||