|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This is a pool of reusuable objects of the same type. All Object pools implement this type, even custom ones. It can be obtained by calling the ObjectPoolManager.getPool method. This will reuse an existing pool if one already existed, otherwise, a new pool is created. ObjectPools returned by getPool are shared in a JVM.
The ObjectPoolManager.createFastPool method also returns ObjectPools. These are unsynchronized pools that offer a very high level of performance but they are not thread safe.
Here is an example of its usage, first get an ObjectPoolManager instance. See the java docs for that type for an example of how to do that.
ObjectPoolManager opm = ...; ObjectPool vectorPool = opm.getPool(Vector.class); Vector pooledVector = null; try { pooledVector = (Vector)vectorPool.getObject(); Now use the vector. } finally { if(pooledVector != null) { vectorPool.returnObject(pooledVector); pooledVector = null; } }
ObjectPool
Method Summary | |
---|---|
java.lang.Object |
getObject()
This returns an object from the pool. |
void |
returnObject(java.lang.Object o)
This should be used to return an object to the pool. |
Method Detail |
public java.lang.Object getObject()
public void returnObject(java.lang.Object o)
Objects that are Collections are automatically cleared when returned to the pool. Collections can only be pooled by the ObjectPool if they support the optional clear method on the Collection interface.
o
- The object to be returned to the pool. This must be the expected type.
java.lang.UnsupportedOperationException
- if the object being returned is a Collection
that doesn't support the clear method.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |