|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Observable
edu.northwestern.at.utils.db.jdbc.SimpleConnectionPool
public class SimpleConnectionPool
A simple JDBC connection pool.
Pool parameters are specified via a Properties object passed to the constructor. The following properties are used:
The pool starts out empty (no connections). When a connection is requested from the pool, if maxPoolSize connections have already been checked out, an exception is thrown. Otherwise, if the pool is not empty, the most recently used connection is checked out from the pool, tested, and returned. If the pool is empty, a new connection is created and returned.
Connections are tested when they are checked out. If a connection is bad, it is closed and a new one is created. The test query statement is "select 1".
Simple connection pools are observable. Observers are notified whenever a bad connection is detected in the test and whenever it takes more than one try to obtain a new connection. The parameter passed to the observer is an array of objects of length 2. For a bad connection, the first element is the Integer 1 and the second element is the exception describing the error, if any. For more than one try, the first element is the Integer 2 and the second element is the number of tries.
The pool is examined every minute. Any connections in the pool which have not been used for idleTimout seconds are closed and removed from the pool.
Simple connection pools are thread-safe.
Constructor Summary | |
---|---|
SimpleConnectionPool(java.util.Properties poolProperties)
Creates a connection pool. |
Method Summary | |
---|---|
void |
close()
Closes the pool. |
java.sql.Connection |
getConnection()
Gets a connection from the pool. |
void |
releaseConnection(java.sql.Connection connection)
Releases a connection back to the pool. |
Methods inherited from class java.util.Observable |
---|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimpleConnectionPool(java.util.Properties poolProperties) throws java.sql.SQLException
poolProperties
- Properties for pool.
java.sql.SQLException
Method Detail |
---|
public java.sql.Connection getConnection() throws java.sql.SQLException
java.sql.SQLException
public void releaseConnection(java.sql.Connection connection)
connection
- The connection to return to the pool. public void close()
The pool may not be reused after it is closed. All connections are closed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |