|
IBM WebSphere Application ServerTM Release 8 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ObjectPool
This is a pool of reusuable objects of the same type. All object pools implement this type, even custom object pools. An object pool can be obtained by calling the ObjectPoolManager.getPool method. This will reuse an existing pool if one already exists. Otherwise, a new pool is created. Object pools returned by getPool are shared in a JVM.
The ObjectPoolManager.createFastPool method also returns object pools. These are unsynchronized pools that offer a very high level of performance, but they are not thread safe.
Here is an example of usage for an object pool. First, get an ObjectPoolManager instance. See the ObjectPoolManager JavaDoc for an example. Then, request an object pool of the desired class. Use the object pool to manage instances of the class as follows.
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; } }
finally
block to ensure objects obtained from a
pool are returned. If an object is not returned then the
memory used by the object can eventually be freed by Java garbage collection.
ObjectPool
Method Summary | |
---|---|
java.lang.Object |
getObject()
This method obtains an object from the pool. |
void |
returnObject(java.lang.Object o)
This should be used to return an object to the pool. |
Method Detail |
---|
java.lang.Object getObject()
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.
|
IBM WebSphere Application ServerTM Release 8 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |