public class SoftReferenceObjectPool extends BaseObjectPool implements ObjectPool
SoftReference based
ObjectPool.| Constructor and Description |
|---|
SoftReferenceObjectPool()
Create a
SoftReferenceObjectPool without a factory. |
SoftReferenceObjectPool(PoolableObjectFactory factory)
Create a
SoftReferenceObjectPool with the specified factory. |
| Modifier and Type | Method and Description |
|---|---|
void |
addObject()
Create an object, and place it into the pool.
|
java.lang.Object |
borrowObject()
Obtains an instance from the pool.
|
void |
clear()
Clears any objects sitting idle in the pool.
|
void |
close()
Close this pool.
|
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(java.lang.Object obj)
Invalidates an object from the pool.
|
void |
returnObject(java.lang.Object obj)
Returns an instance to the pool.
|
void |
setFactory(PoolableObjectFactory factory)
Sets the
factory this pool uses
to create new instances. |
public SoftReferenceObjectPool()
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.public SoftReferenceObjectPool(PoolableObjectFactory factory)
SoftReferenceObjectPool with the specified factory.factory - object factory to use.public void addObject()
throws java.lang.Exception
addObject in interface ObjectPooladdObject in class BaseObjectPooljava.lang.Exception - when PoolableObjectFactory.makeObject() fails.java.lang.IllegalStateException - after ObjectPool.close() has been called on this pool.java.lang.UnsupportedOperationException - when this pool cannot add new idle objects.public java.lang.Object borrowObject()
throws java.lang.Exception
BaseObjectPoolborrowObject in interface ObjectPoolborrowObject in class BaseObjectPooljava.lang.Exception - if an instance cannot be obtained from the poolpublic void clear()
clear in interface ObjectPoolclear in class BaseObjectPoolpublic void close()
throws java.lang.Exception
BaseObjectPoolisClosed and assertOpen.close in interface ObjectPoolclose in class BaseObjectPooljava.lang.Exception - deprecated: implementations should silently fail if not all resources can be freed.public int getNumActive()
getNumActive in interface ObjectPoolgetNumActive in class BaseObjectPoolpublic int getNumIdle()
getNumIdle in interface ObjectPoolgetNumIdle in class BaseObjectPoolpublic void invalidateObject(java.lang.Object obj)
throws java.lang.Exception
BaseObjectPoolobj must have been obtained
using 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.
invalidateObject in interface ObjectPoolinvalidateObject in class BaseObjectPoolobj - a borrowed instance to be disposed.java.lang.Exceptionpublic void returnObject(java.lang.Object obj)
throws java.lang.Exception
BaseObjectPoolreturnObject in interface ObjectPoolreturnObject in class BaseObjectPoolobj - instance to return to the pooljava.lang.Exceptionpublic void setFactory(PoolableObjectFactory factory) throws java.lang.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.java.lang.IllegalStateException - when the factory cannot be set at this timeCopyright © 2001-2003 Apache Software Foundation. Documenation generated November 21 2014.