|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.pool.BaseObjectPool
org.apache.commons.pool.impl.SoftReferenceObjectPool
public class SoftReferenceObjectPool
A SoftReference based
ObjectPool.
| Constructor Summary | |
|---|---|
SoftReferenceObjectPool()
Deprecated. to be removed in pool 2.0. Use SoftReferenceObjectPool(PoolableObjectFactory). |
|
SoftReferenceObjectPool(PoolableObjectFactory factory)
Create a SoftReferenceObjectPool with the specified factory. |
|
SoftReferenceObjectPool(PoolableObjectFactory factory,
int initSize)
Deprecated. because this is a SoftReference pool, prefilled idle obejects may be garbage collected before they are used. To be removed in Pool 2.0. |
|
| Method Summary | |
|---|---|
void |
addObject()
Create an object, and place it into the pool. |
Object |
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. |
PoolableObjectFactory |
getFactory()
Returns the PoolableObjectFactory 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(Object obj)
Invalidates an object from the pool. |
void |
returnObject(Object obj)
Returns an instance to the pool after successful validation and passivation. |
void |
setFactory(PoolableObjectFactory factory)
Deprecated. to be removed in pool 2.0 |
| Methods inherited from class org.apache.commons.pool.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()
SoftReferenceObjectPool(PoolableObjectFactory).
SoftReferenceObjectPool without a factory.
setFactory should be called
before any attempts to use the pool are made.
Generally speaking you should prefer the SoftReferenceObjectPool(PoolableObjectFactory) constructor.
SoftReferenceObjectPool(PoolableObjectFactory)public SoftReferenceObjectPool(PoolableObjectFactory factory)
SoftReferenceObjectPool with the specified factory.
factory - object factory to use.
public SoftReferenceObjectPool(PoolableObjectFactory factory,
int initSize)
throws Exception,
IllegalArgumentException
SoftReferenceObjectPool with the specified factory and initial idle object count.
factory - object factory to use.initSize - initial size to attempt to prefill the pool.
Exception - when there is a problem prefilling the pool.
IllegalArgumentException - when factory is null.| Method Detail |
|---|
public Object borrowObject()
throws Exception
Borrow an object from the pool. If there are no idle instances available in the pool, the configured
factory's PoolableObjectFactory.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 ObjectPoolborrowObject in class BaseObjectPoolNoSuchElementException - 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(Object 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:
validation failspassivation throws an exceptionExceptions passivating or destroying instances are silently swallowed. Exceptions validating instances are propagated to the client.
returnObject in interface ObjectPoolreturnObject in class BaseObjectPoolobj - instance to return to the pool
Exception
public void invalidateObject(Object obj)
throws Exception
Invalidates an object from the pool.
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 ObjectPoolinvalidateObject in class BaseObjectPoolobj - a borrowed instance to be disposed.
Exception
public void addObject()
throws Exception
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
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 ObjectPooladdObject in class BaseObjectPoolIllegalStateException - if invoked on a closed pool
Exception - when the factory has a problem creating or passivating an object.public int getNumIdle()
getNumIdle in interface ObjectPoolgetNumIdle in class BaseObjectPoolpublic int getNumActive()
getNumActive in interface ObjectPoolgetNumActive in class BaseObjectPoolpublic void clear()
clear in interface ObjectPoolclear in class BaseObjectPool
public void close()
throws Exception
Close this pool, and free any resources associated with it. Invokes
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 ObjectPoolclose in class BaseObjectPoolException - never - exceptions clearing the pool are swallowed
public void setFactory(PoolableObjectFactory factory)
throws IllegalStateException
factory this pool uses
to create new instances. Trying to change
the factory while there are borrowed objects will
throw an IllegalStateException.
setFactory in interface ObjectPoolsetFactory in class BaseObjectPoolfactory - the PoolableObjectFactory used to create new instances.
IllegalStateException - when the factory cannot be set at this timepublic PoolableObjectFactory getFactory()
PoolableObjectFactory 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 | |||||||||