Top Description Fields Constructors Methods
org.apache.commons.pool2

public abstract Class BaseObjectPool<T>

extends BaseObject
implements ObjectPool<T>
Class Inheritance
All Implemented Interfaces
org.apache.commons.pool2.ObjectPool, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.apache.commons.pool2.impl.SoftReferenceObjectPool
Type Parameters
<T>
Type of element pooled in this pool.

A simple base implementation of ObjectPool. Optional operations are implemented to either do nothing, return a value indicating it is unsupported or throw UnsupportedOperationException.

This class is intended to be thread-safe.

Since
2.0

Field Summary

Modifier and TypeField and Description
private volatile boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addObject()

Implements org.apache.commons.pool2.ObjectPool.addObject.

Not supported in this base implementation.
protected final void
assertOpen()

Throws an IllegalStateException when this pool has been closed.

public abstract T
borrowObject()

Redeclares org.apache.commons.pool2.ObjectPool.borrowObject.

Borrows an instance from this pool.
public void
clear()

Implements org.apache.commons.pool2.ObjectPool.clear.

Not supported in this base implementation.
public void
close()

Implements org.apache.commons.pool2.ObjectPool.close.

Closes this pool, and free any resources associated with it.
public int

Returns:

a negative value.
getNumActive
()

Implements org.apache.commons.pool2.ObjectPool.getNumActive.

Not supported in this base implementation.
public int

Returns:

a negative value.
getNumIdle
()

Implements org.apache.commons.pool2.ObjectPool.getNumIdle.

Not supported in this base implementation.
public abstract void
invalidateObject(T
a borrowed instance to be disposed.
obj
)

Redeclares org.apache.commons.pool2.ObjectPool.invalidateObject.

Invalidates an object from the pool.
public final boolean

Returns:

true when this pool has been closed.
isClosed
()

Has this pool instance been closed.

public abstract void
returnObject(T
a borrowed instance to be returned.
obj
)

Redeclares org.apache.commons.pool2.ObjectPool.returnObject.

Returns an instance to the pool.
protected void
toStringAppendFields(final StringBuilder
Field names and values are appended to this object
builder
)

Overrides org.apache.commons.pool2.BaseObject.toStringAppendFields.

Used by sub-classes to include the fields defined by the sub-class in the toString() output.
Inherited from org.apache.commons.pool2.BaseObject:
toString

Field Detail

closedback to summary
private volatile boolean closed

Constructor Detail

BaseObjectPoolback to summary
public BaseObjectPool()

Method Detail

addObjectback to summary
public void addObject() throws Exception

Implements org.apache.commons.pool2.ObjectPool.addObject.

Not supported in this base implementation. Subclasses should override this behavior.

Annotations
@Override
Exceptions
Exception:

Doc from org.apache.commons.pool2.ObjectPool.addObject.

when PooledObjectFactory#makeObject fails.

UnsupportedOperationException:
if the pool does not implement this method
assertOpenback to summary
protected final void assertOpen() throws IllegalStateException

Throws an IllegalStateException when this pool has been closed.

Exceptions
IllegalStateException:
when this pool has been closed.
See Also
isClosed()
borrowObjectback to summary
public abstract T borrowObject() throws Exception

Redeclares org.apache.commons.pool2.ObjectPool.borrowObject.

Doc from org.apache.commons.pool2.ObjectPool.borrowObject.

Borrows an instance from this pool.

Instances returned from this method will have been either newly created with PooledObjectFactory#makeObject or will be a previously idle object and have been activated with PooledObjectFactory#activateObject and then validated with PooledObjectFactory#validateObject.

By contract, clients must return the borrowed instance using returnObject, invalidateObject, or a related method as defined in an implementation or sub-interface.

The behavior of this method when the pool has been exhausted is not strictly specified (although it may be specified by implementations).

Returns:T

an instance from this pool.

Annotations
@Override
Exceptions
Exception:
when PooledObjectFactory#makeObject throws an exception.
clearback to summary
public void clear() throws Exception

Implements org.apache.commons.pool2.ObjectPool.clear.

Not supported in this base implementation.

Annotations
@Override
Exceptions
Exception:

Doc from org.apache.commons.pool2.ObjectPool.clear.

if the pool cannot be cleared

UnsupportedOperationException:
if the pool does not implement this method
closeback to summary
public void close()

Implements org.apache.commons.pool2.ObjectPool.close.

Doc from org.apache.commons.pool2.ObjectPool.close.

Closes this pool, and free any resources associated with it.

Calling addObject or borrowObject after invoking this method on a pool will cause them to throw an IllegalStateException.

Implementations should silently fail if not all resources can be freed.

This affects the behavior of isClosed and assertOpen.

Annotations
@Override
getNumActiveback to summary
public int getNumActive()

Implements org.apache.commons.pool2.ObjectPool.getNumActive.

Not supported in this base implementation.

Returns:int

a negative value.

Annotations
@Override
getNumIdleback to summary
public int getNumIdle()

Implements org.apache.commons.pool2.ObjectPool.getNumIdle.

Not supported in this base implementation.

Returns:int

a negative value.

Annotations
@Override
invalidateObjectback to summary
public abstract void invalidateObject(T obj) throws Exception

Redeclares org.apache.commons.pool2.ObjectPool.invalidateObject.

Doc from org.apache.commons.pool2.ObjectPool.invalidateObject.

Invalidates an object from the pool.

By contract, obj 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.

Parameters
obj:T

a borrowed instance to be disposed.

Annotations
@Override
Exceptions
Exception:
if the instance cannot be invalidated
isClosedback to summary
public final boolean isClosed()

Has this pool instance been closed.

Returns:boolean

true when this pool has been closed.

returnObjectback to summary
public abstract void returnObject(T obj) throws Exception

Redeclares org.apache.commons.pool2.ObjectPool.returnObject.

Doc from org.apache.commons.pool2.ObjectPool.returnObject.

Returns an instance to the pool. By contract, obj must have been obtained using borrowObject() or a related method as defined in an implementation or sub-interface.

Parameters
obj:T

a borrowed instance to be returned.

Annotations
@Override
Exceptions
Exception:
if an instance cannot be returned to the pool
toStringAppendFieldsback to summary
protected void toStringAppendFields(final StringBuilder builder)

Overrides org.apache.commons.pool2.BaseObject.toStringAppendFields.

Doc from org.apache.commons.pool2.BaseObject.toStringAppendFields.

Used by sub-classes to include the fields defined by the sub-class in the toString() output.

Parameters
builder:StringBuilder

Field names and values are appended to this object

Annotations
@Override