org.apache.jdo.util
Class Pool

java.lang.Object
  extended byorg.apache.jdo.util.Pool

public class Pool
extends java.lang.Object

A general purpose pooling class.

Author:
Dave Bristor

Field Summary
private  int count
           
private static I18NHelper msg
          I18N
private  int size
           
private  java.util.Stack stack
           
(package private) static org.apache.commons.logging.Log test
           
private  int waitMillis
          Number of millis to wait for a free entry Currently fixed; might be made configurable in future.
private  int waitNumber
          Number of times to wait for a free entry Currently fixed; might be made configurable in future.
 
Constructor Summary
Pool(int size)
          Constructs a pool that will limit the number of objects which it can contain.
 
Method Summary
 java.lang.Object get()
          Gets an object from the pool, if one is available.
 void put(java.lang.Object o)
          Puts the given object into the pool, if there the pool has fewer than the number of elements specifed when created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stack

private final java.util.Stack stack

size

private final int size

count

private int count

waitMillis

private int waitMillis
Number of millis to wait for a free entry Currently fixed; might be made configurable in future.


waitNumber

private int waitNumber
Number of times to wait for a free entry Currently fixed; might be made configurable in future.


msg

private static final I18NHelper msg
I18N


test

static final org.apache.commons.logging.Log test
Constructor Detail

Pool

public Pool(int size)
Constructs a pool that will limit the number of objects which it can contain.

Parameters:
size - The maximum number of items that can be put into the pool.
Method Detail

put

public void put(java.lang.Object o)
         throws java.lang.InterruptedException
Puts the given object into the pool, if there the pool has fewer than the number of elements specifed when created. If the pool is full, blocks until an element is removed.

Parameters:
o - Object to be put in the pool.
Throws:
java.lang.InterruptedException

get

public java.lang.Object get()
                     throws java.lang.InterruptedException
Gets an object from the pool, if one is available. If an object is not available, waits until one is. The waiting is governed by two variables, which are currently fixed: waitMillis and waitNumber. If no object is available from the pool within (waitNumber) times (waitMillis) milliseconds, then a RuntimeException is thrown. In future, the waitMillis and waitNumber should be configurable.

Returns:
An object from the pool.
Throws:
java.lang.InterruptedException