Oracle

com.compoze.util
Class ObjectFactoryPool

java.lang.Object
  extended by 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.


Nested Class Summary
static class ObjectFactoryPool.ThreadUnsafeObject
          This class is a test class that is not thread-safe.
 
Constructor Summary
ObjectFactoryPool(IObjectFactory factory)
          Constructor.
ObjectFactoryPool(IObjectFactory factory, int iInitialSize, int iMinimumAvailableSize, int iIncrement)
          Constructor.
 
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
 

Constructor Detail

ObjectFactoryPool

public ObjectFactoryPool(IObjectFactory factory)
Constructor.


ObjectFactoryPool

public ObjectFactoryPool(IObjectFactory factory,
                         int iInitialSize,
                         int iMinimumAvailableSize,
                         int iIncrement)
Constructor.

Method Detail

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.


Oracle

Copyright ©1999-2008 Oracle All rights reserved.