| Modifier and Type | Field and Description |
|---|---|
| private final ArrayList | allReferences
All references - checked out or waiting to be borrowed. |
| private long | createCount
Total number of instances that have been created |
| private long | destroyCount
Total number of instances that have been destroyed |
| private final PooledObjectFactory | factory
Factory to source pooled objects |
| private final LinkedBlockingDeque | idleReferences
Idle references - waiting to be borrowed |
| private int | numActive
Count of instances that have been checkout out to pool clients |
| private final ReferenceQueue | refQueue
Queue of broken references that might be able to be removed from
|
| Access | Constructor and Description |
|---|---|
| public | SoftReferenceObjectPool(final PooledObjectFactory<T>
object factory to use. factory)Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | addObject()
Overrides org. Implements org. |
| public synchronized T | Returns: a valid, activated object instanceImplements abstract org. Implements org. |
| public synchronized void | clear()
Overrides org. Implements org. |
| public void | close()
Overrides org. Implements org. |
| private void | destroy(final PooledSoftReference<T>
PooledSoftReference to destroy toDestroy)Destroys a |
| private PooledSoftReference | Returns: PooledSoftReference wrapping a soft reference to objreturning object obj)Finds the PooledSoftReference in allReferences that points to obj. |
| public synchronized PooledObjectFactory | Returns: the factoryGets the |
| public synchronized int | Returns: the number of instances currently borrowed from this poolOverrides org. Implements org. |
| public synchronized int | Returns: estimated number of idle instances in the poolOverrides org. Implements org. |
| public synchronized void | invalidateObject(final T
a obj)borrowed instance to be disposed.Implements abstract org. Implements org. |
| private void | pruneClearedReferences()
If any idle objects were garbage collected, remove their
|
| private void | removeClearedReferences(final Iterator<PooledSoftReference<T>>
iterator over idle/allReferences iterator)Clears cleared references from iterator's collection |
| public synchronized void | returnObject(final T
instance to return to the pool obj)Implements abstract org. Implements org. |
| protected void | toStringAppendFields(final StringBuilder
Field names and values are appended to this object builder)Overrides org. toString() output.
|
| allReferences | back to summary |
|---|---|
| private final ArrayList<PooledSoftReference<T>> allReferences All references - checked out or waiting to be borrowed. | |
| createCount | back to summary |
|---|---|
| private long createCount Total number of instances that have been created | |
| destroyCount | back to summary |
|---|---|
| private long destroyCount Total number of instances that have been destroyed | |
| factory | back to summary |
|---|---|
| private final PooledObjectFactory<T> factory Factory to source pooled objects | |
| idleReferences | back to summary |
|---|---|
| private final LinkedBlockingDeque<PooledSoftReference<T>> idleReferences Idle references - waiting to be borrowed | |
| numActive | back to summary |
|---|---|
| private int numActive Count of instances that have been checkout out to pool clients | |
| refQueue | back to summary |
|---|---|
| private final ReferenceQueue<T> refQueue Queue of broken references that might be able to be removed from
| |
| SoftReferenceObjectPool | back to summary |
|---|---|
| public SoftReferenceObjectPool(final PooledObjectFactory<T> factory) Constructs a
| |
| addObject | back to summary |
|---|---|
| public synchronized void addObject() throws Exception Overrides org. Implements org. Creates an object, and places 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
| |
| borrowObject | back to summary |
|---|---|
| public synchronized T borrowObject() throws Exception Implements abstract org. Implements org. Borrows an object from the pool. If there are no idle instances available
in the pool, the configured factory's
All instances are
| |
| clear | back to summary |
|---|---|
| public synchronized void clear() Overrides org. Implements org. Clears any objects sitting idle in the pool.
| |
| close | back to summary |
|---|---|
| public void close() Overrides org. Implements org. Closes this pool, and frees any resources associated with it. Invokes
Calling
| |
| destroy | back to summary |
|---|---|
| private void destroy(final PooledSoftReference<T> toDestroy) throws Exception Destroys a
| |
| findReference | back to summary |
|---|---|
| private PooledSoftReference Finds the PooledSoftReference in allReferences that points to obj.
| |
| getFactory | back to summary |
|---|---|
| public synchronized PooledObjectFactory Gets the
| |
| getNumActive | back to summary |
|---|---|
| public synchronized int getNumActive() Overrides org. Implements org. Gets the number of instances currently borrowed from this pool.
| |
| getNumIdle | back to summary |
|---|---|
| public synchronized int getNumIdle() Overrides org. Implements org. Gets an approximation not less than the of the number of idle instances in the pool.
| |
| invalidateObject | back to summary |
|---|---|
| public synchronized void invalidateObject(final T obj) throws Exception Implements abstract org. Implements org. Doc from org. Invalidates an object from the pool.
By contract, This method should be used when an object that has been borrowed is determined (due to an exception or other problem) to be invalid. | |
| pruneClearedReferences | back to summary |
|---|---|
| private void pruneClearedReferences() If any idle objects were garbage collected, remove their
| |
| removeClearedReferences | back to summary |
|---|---|
| private void removeClearedReferences(final Iterator<PooledSoftReference<T>> iterator) Clears cleared references from iterator's collection
| |
| returnObject | back to summary |
|---|---|
| public synchronized void returnObject(final T obj) throws Exception Implements abstract org. Implements org. Returns an instance to the pool after successful validation and passivation. The returning instance is destroyed if any of the following are true:
| |
| toStringAppendFields | back to summary |
|---|---|
| protected void toStringAppendFields(final StringBuilder builder) Overrides org. Doc from org. Used by sub-classes to include the fields defined by the sub-class in the
| |