com.ibm.websphere.asynchbeans.pool

Interface ObjectPoolManager



  • public interface ObjectPoolManager
    This acts as a factory for object pools. An administrator can create one or more ObjectPoolManagers and bind them in to JNDI using wsadmin or the administrative console. The ObjectPoolManager screen can be found in the administrative console by clicking on Resources and then ObjectPools.

    The Administrator can define one or more ObjectPoolManagers here. Such an ObjectPoolManager can be used by an application to act as a factory for creating or reusing an already created object pool for a specific Java type. Any Java object that has a public default constructor can be pooled out of the box using the default implementation.

    If your application needs to pool an object that doesn't meet that criteria or if your application wants to be informed when objects are taken and returned from/to the object pool then the administrator can define a custom ObjectPool. When the administrator creates an ObjectPoolManager then the administrator can also define zero or more custom Object pools also. A custom object pool is a non sychronized object that implements the CustomObjectPool interface. Each custom pool must be registered using the admin and the class name of the type to be pooled, the class implementing the CustomObjectPool and any custom properties must be specified. If an application then uses this ObjectPoolManager and requests a pool for this type then an instance of the CustomObjectPool is used to implement that pool.

    If an object that is a Java 2 Collection is pooled then such objects are automatically cleared when they are returned to the pool by an application. This behaviour is implemented by the default pool handler. If a custom object pool is provided then the implemented should copy this behaviour.

    Applications that need an object pool should include a resource-ref to an ObjectPoolManager in their J2EE component (EJB or webapp). The application containing that component can then be bound to a administrator created ObjectPoolManager at deploy time. The J2EE component can then retrieve this ObjectPoolManager using the following code:


     InitialContext ic = new InitialContext();
     ObjectPoolManager opm = (ObjectPoolManager)ic.lookup("java:comp/env/opm/myObjectPoolManager");
     

    This example assumes that the J2EE component had a resource-ref called 'opm/myObjectPoolManager'. PMI statistics are not available for Custom Object Pools.

    If you are sharing an object pool between applications that care needs to be taken to avoid class loader problems. This isn't an issue when pooling JDK supplied objects but if you are pooling application objects then it may occur. We recommend that pools not be shared between applications when application objects are being pooled.

    Every ObjectPool also has a JMX MBean associated with it. The MBean can be used to flush idle instances of the object being pooled.

    See Also:
    ObjectPool, CustomObjectPool
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      ObjectPool createFastPool(java.lang.Class aClass)
      This returns a pool for managing instances of a class.
      ObjectPool getPool(java.lang.Class aClass)
      This returns a pool for managing instances of a class.
    • Method Detail

      • getPool

        ObjectPool getPool(java.lang.Class aClass)
                           throws java.lang.InstantiationException,
                                  java.lang.IllegalAccessException
        This returns a pool for managing instances of a class. The class must be public and have a public default constructor or else the IllegalAccessException is thrown. If the class cannot be instantiated then instantiation is thrown. The pool returned is thread safe.

        ObjectPools for Java 2 collection based classes are automatically cleared when returned to the pool.

        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
      • createFastPool

        ObjectPool createFastPool(java.lang.Class aClass)
                                  throws java.lang.InstantiationException,
                                         java.lang.IllegalAccessException
        This returns a pool for managing instances of a class. The class must be public and have a public default constructor or else the IllegalAccessException is thrown. If the class cannot be instantiated then instantiation is thrown. The pool returned is not thread safe. This pool should be used on a single thread only. This is provided to avoid unnecessary synchronization in single threaded scenarios. An example would be that a Work object creates a fast pool in it's run method. The code called by run can then use this pool for applications requiring very high performance. Only code directly called from the Work.run method should use this fast object pool, this ensures that only a single thread can use it.

        ObjectPools for Java 2 collection based classes are automatically cleared when returned to the pool.

        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
IBM WebSphere Application ServerTM
Release 9.0