com.compoze.util
Class ObjectFactoryPool
java.lang.Object
|
+--com.compoze.util.ObjectFactoryPool
- public class ObjectFactoryPool
- extends java.lang.Object
This class keeps a pool of objects that may be obtained in a thread-safe
fashion. When it becomes empty it is filled when new objects
instantiated by an implementation of IObjectFactory. Client code should
do something like the following to use this class to insure that instances
are properly returned to the pool:
Object obj = null;
try
{
Object obj = pool.get ();
// ... do something with obj
}
finally
{
if (null != obj)
pool.put (obj);
}
This pool is particularly useful for large objects that take a long time
to instantiate and are not thread-safe (for example, XML parser factories),
and when clients spend a long time using them such that synchronization
around one object would bottleneck performance.
Method Summary |
java.lang.Object |
get()
Gets an object from the pool, waiting until one is available. |
static void |
main(java.lang.String[] args)
Main. |
void |
put(java.lang.Object obj)
Puts an object back into the pool. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ObjectFactoryPool
public ObjectFactoryPool(IObjectFactory factory)
- Constructor.
ObjectFactoryPool
public ObjectFactoryPool(IObjectFactory factory,
int iInitialSize,
int iMinimumAvailableSize,
int iIncrement)
- Constructor.
get
public java.lang.Object get()
- Gets an object from the pool, waiting until one is available.
put
public void put(java.lang.Object obj)
- Puts an object back into the pool.
main
public static void main(java.lang.String[] args)
- Main.
Copyright ©1999-2003 Compoze Software, Inc. All rights reserved.