Usage

In order to use PooliT, you need to identify a particular class you wish to pool. The easiest type of class to pool are classes that provide a no-argument constructors. These classes can be instantiated easily at runtime given the class name.

For example, if you have a class named Foo that you wish to pool. The Foo class defines a no-argument constructor.

public class Foo {
   public Foo() { // no-argument constructor
      // do initialization here
   }
   // rest of source code...
}

If you wanted to pool Foo using the FixedPooler with a maximum capacity of 10 object in the pool, then you would initialize the pool as follows:

Pooler pool = new FixedPooler(Foo.class, 10);

You can replace FixedPooler with any one of the other Poolers provided with PooliT or a custom implementation of Pooler by simply calling the appropriate constructor and passing the appropriate intialization parameters.

Now in your source code, instead of instantiating Foo classes using the new operator, you would get them from the pool as follows:

Foo f = (Foo)pool.fetch(); // instead of new Foo();

When you are finished using the object, you can return it to the pool for re-use by calling the release method:

pool.release(f);

Don't forget to return objects back to the pool or else your pool will run out of objects in its pool and may be required to instantiate more objects. Try to use a Pooler that best suits the needs and usage pattern of your application.