de.cau.cs.kieler.core.alg
Class InstancePool<T>

java.lang.Object
  extended by de.cau.cs.kieler.core.alg.InstancePool<T>
Type Parameters:
T - the type of instances that are held by this pool

public class InstancePool<T>
extends Object

A pool for class instances.

Rating red

Field Summary
static int INFINITE
          an infinite amount of instances.
 
Constructor Summary
InstancePool(IFactory<T> thefactory)
          Create an instance pool with an infinite capacity.
InstancePool(IFactory<T> thefactory, int thelimit)
          Create an instance pool with given capacity.
 
Method Summary
 void clear()
          Clear the instance pool by disposing all instances that are currently held.
 T fetch()
          Fetch an instance from the pool.
 void release(T obj)
          Release an instance into the pool to be used again.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INFINITE

public static final int INFINITE
an infinite amount of instances.

See Also:
Constant Field Values
Constructor Detail

InstancePool

public InstancePool(IFactory<T> thefactory)
Create an instance pool with an infinite capacity.

Parameters:
thefactory - the instance factory

InstancePool

public InstancePool(IFactory<T> thefactory,
                    int thelimit)
Create an instance pool with given capacity.

Parameters:
thefactory - the instance factory
thelimit - the maximal number of instances that shall be kept in the pool
Method Detail

fetch

public T fetch()
Fetch an instance from the pool. If no instance is available, a new one is created.

Returns:
a class instance

release

public void release(T obj)
Release an instance into the pool to be used again. Only instances that are still usable may be released.

Parameters:
obj - a class instance

clear

public void clear()
Clear the instance pool by disposing all instances that are currently held.