net.jot.db
Class JOTDBPool

java.lang.Object
  extended by java.lang.Thread
      extended by net.jot.db.JOTDBPool
All Implemented Interfaces:
java.lang.Runnable

public class JOTDBPool
extends java.lang.Thread

This is an implementation of a database connection pooling system It manages connections, adds some when needed, and periodically check there status and renew them is they appear corrupt/hung. It also release connections if they aren't used for a while.

Author:
tcolar

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
JOTDBPool(java.lang.String name, JOTDBJDBCSetup setup)
          Create appol for a particular DB
 
Method Summary
 void dropAll()
          Release/closes all the connections
 void dropConnection(int i)
          Release/removes a connection
 void finalize()
          will automatically call shutdown when java app is terminated, to avoid hung DB connections.
 void releaseConnection(java.sql.Connection con, int i)
          Description of the Method
 void releaseConnection(JOTTaggedConnection con)
          free a connection when not usefull anymore.
 java.sql.Connection renewConnection(int index)
          Renew a connection when it got corrupted.
 JOTTaggedConnection retrieveConnection()
          This get a connection from the pool Returns the "first available".
 void run()
          The run thread method is there as a whatchdog It will try to find out when connections aren't needed anymore And free them if possible.
 void shutdown()
          Terminates a pool and releases resources
 void updateAccessTime(int id)
          Updates the last time a pooled connection was used, so we can manage it better.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JOTDBPool

public JOTDBPool(java.lang.String name,
                 JOTDBJDBCSetup setup)
Create appol for a particular DB

Parameters:
setup - Description of Parameter
Method Detail

run

public void run()
The run thread method is there as a whatchdog It will try to find out when connections aren't needed anymore And free them if possible. It also frees "locked" connections. This should be threadsafe.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

releaseConnection

public void releaseConnection(JOTTaggedConnection con)
free a connection when not usefull anymore.

Parameters:
con - Description of Parameter

releaseConnection

public void releaseConnection(java.sql.Connection con,
                              int i)
Description of the Method

Parameters:
con - Description of the Parameter
i - Description of the Parameter

retrieveConnection

public JOTTaggedConnection retrieveConnection()
This get a connection from the pool Returns the "first available". This is synchronized since multithread.

Returns:
The connection value

renewConnection

public java.sql.Connection renewConnection(int index)
Renew a connection when it got corrupted.

Parameters:
index - Description of Parameter
Returns:
Description of the Returned Value

dropConnection

public void dropConnection(int i)
Release/removes a connection

Parameters:
i - Description of the Parameter

dropAll

public void dropAll()
Release/closes all the connections


shutdown

public void shutdown()
Terminates a pool and releases resources


finalize

public void finalize()
will automatically call shutdown when java app is terminated, to avoid hung DB connections.

Overrides:
finalize in class java.lang.Object

updateAccessTime

public void updateAccessTime(int id)
Updates the last time a pooled connection was used, so we can manage it better.

Parameters:
dataId - Description of the Parameter