org.knime.core.util
Class ObjectPool<T>

java.lang.Object
  extended by org.knime.core.util.ObjectPool<T>
Type Parameters:
T - any class whose objects are stored in the pool

public class ObjectPool<T>
extends Object

Implements a simple pool for reusable objects. The pool can be divided into several sub pools, e.g. if the objects have different "sizes". If memory becomes scarce some of the sub pools may get garbage collected, but this is transparent.

Author:
Thorsten Meinl, University of Konstanz

Constructor Summary
ObjectPool(int subPools, int maxSizes)
          Creates a new object pool.
 
Method Summary
 T get(int subPool)
          Returns an object from the (sub) pool, or null if the pool is empty.
 void printStats(PrintStream out)
          Prints statistics about hits and misses.
 void recycle(T object, int subPool)
          Puts an object into the specified subpool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectPool

public ObjectPool(int subPools,
                  int maxSizes)
Creates a new object pool.

Parameters:
subPools - the number of sub pools
maxSizes - the maximum size of each sub pool
Method Detail

get

public T get(int subPool)
Returns an object from the (sub) pool, or null if the pool is empty.

Parameters:
subPool - the number of the sub pool, starting with 0
Returns:
an object or null

recycle

public void recycle(T object,
                    int subPool)
Puts an object into the specified subpool. If the pool is already full, the object will not be added, in this case the method does nothing.

Parameters:
object - an object to store
subPool - the index of the sub pool (starting with 0)

printStats

public void printStats(PrintStream out)
Prints statistics about hits and misses.

Parameters:
out - a print stream to which the statistic should be written


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.