Class ConnectionPool

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--ConnectionPool
All Implemented Interfaces:
java.lang.Runnable

public class ConnectionPool
extends java.lang.Thread

This is a Connection pool. It uses RestartableThread.


Field Summary
static int DEFAULT_SLEEP_TIME
          manager will use it as sleep time if connections are still available
 java.util.Vector free_threads
           
protected  java.lang.Thread manager
          Thread used to manage the pool
static int URGENT_SLEEP_TIME
          manager will use it s sleep time if no more connections are available
 java.util.Vector used_threads
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ConnectionPool(int maxThread, int minThread, int maxSpareThread, int minSpareThread)
          Create a ConectionPool.
 
Method Summary
 Connection getConnection()
          Get a Thread.
 int getMaxSpareThread()
          Get the current max of free threads.
 int getMaxThread()
          Get the current max of concurrent threads.
 int getMinSpareThread()
          Get the current min of free threads.
 int getMinThread()
          Get the current min of concurrent threads.
 void killConnection(Connection c)
          Kills a connection given its reference
 void returnConnection(Connection c)
          Return a thread to the pool.
 void run()
          The cleaner thread is used to maintain the number of threads within the values defined by MAX_THREAD, MIN_THREAD, MAX_SPARE_THREAD and MIN_SPARE_THREAD
 void setMaxSpareThread(int maxSpareThread)
          Set the max number of free threads
 void setMaxThread(int maxThread)
          Set the max number of threads,
 void setMinSpareThread(int minSpareThread)
          Set the min number of free threads
 void setMinThread(int minThread)
          Set the min number of threads
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

free_threads

public java.util.Vector free_threads

used_threads

public java.util.Vector used_threads

manager

protected java.lang.Thread manager
Thread used to manage the pool

DEFAULT_SLEEP_TIME

public static int DEFAULT_SLEEP_TIME
manager will use it as sleep time if connections are still available

URGENT_SLEEP_TIME

public static int URGENT_SLEEP_TIME
manager will use it s sleep time if no more connections are available
Constructor Detail

ConnectionPool

public ConnectionPool(int maxThread,
                      int minThread,
                      int maxSpareThread,
                      int minSpareThread)
Create a ConectionPool.
Parameters:
maxThread - max number of concurrent threads.
minThread - min number of concurrent threads.
maxSpareThread - max number of free (unused) threads.
minSpareThread - min number of free (unused) threads.
Method Detail

setMaxThread

public void setMaxThread(int maxThread)
Set the max number of threads,
Parameters:
maxThread - the new max of concurrent threads.

getMaxThread

public int getMaxThread()
Get the current max of concurrent threads.
Returns:
the max number of threads.

setMinThread

public void setMinThread(int minThread)
Set the min number of threads
Parameters:
minThread - the new min of concurrent threads.

getMinThread

public int getMinThread()
Get the current min of concurrent threads.
Returns:
the min number of threads.

setMaxSpareThread

public void setMaxSpareThread(int maxSpareThread)
Set the max number of free threads
Parameters:
maxSpareThread - the new max of free threads.

getMaxSpareThread

public int getMaxSpareThread()
Get the current max of free threads.
Returns:
the max number of free threads.

setMinSpareThread

public void setMinSpareThread(int minSpareThread)
Set the min number of free threads
Parameters:
minSpareThread - the new min of free threads.

getMinSpareThread

public int getMinSpareThread()
Get the current min of free threads.
Returns:
the min number of free threads.

killConnection

public void killConnection(Connection c)
Kills a connection given its reference
Parameters:
c - the Connection to be closed

getConnection

public Connection getConnection()
Get a Thread. This will wait for a thread to be returned if the limit is currently reached.

returnConnection

public void returnConnection(Connection c)
Return a thread to the pool. If the thread was never part of this pool it will be ignored.
Parameters:
c - the Connection to return.

run

public void run()
The cleaner thread is used to maintain the number of threads within the values defined by MAX_THREAD, MIN_THREAD, MAX_SPARE_THREAD and MIN_SPARE_THREAD
Overrides:
run in class java.lang.Thread