java.lang.Object
org.roller.util.ConnectionPool
- All Implemented Interfaces:
- java.lang.Runnable
- public class ConnectionPool
- extends java.lang.Object
- implements java.lang.Runnable
A class for preallocating, recycling, and managing
JDBC connections.
Taken from Core Servlets and JavaServer Pages
from Prentice Hall and Sun Microsystems Press,
http://www.coreservlets.com/.
© 2000 Marty Hall; may be freely used or adapted.
driver
private java.lang.String driver
url
private java.lang.String url
username
private java.lang.String username
password
private java.lang.String password
maxConnections
private int maxConnections
waitIfBusy
private boolean waitIfBusy
availableConnections
private java.util.Vector availableConnections
busyConnections
private java.util.Vector busyConnections
connectionPending
private boolean connectionPending
ConnectionPool
public ConnectionPool(java.lang.String driver,
java.lang.String url,
java.lang.String username,
java.lang.String password,
int initialConnections,
int maxConnections,
boolean waitIfBusy)
throws java.sql.SQLException
getConnection
public java.sql.Connection getConnection()
throws java.sql.SQLException
makeBackgroundConnection
private void makeBackgroundConnection()
run
public void run()
- Description copied from interface:
java.lang.Runnable
- This method will be called by whoever wishes to run your class
implementing Runnable. Note that there are no restrictions on what
you are allowed to do in the run method, except that you cannot
throw a checked exception.
- Specified by:
run in interface java.lang.Runnable
makeNewConnection
private java.sql.Connection makeNewConnection()
throws java.sql.SQLException
free
public void free(java.sql.Connection connection)
totalConnections
public int totalConnections()
closeAllConnections
public void closeAllConnections()
- Close all the connections. Use with caution:
be sure no connections are in use before
calling. Note that you are not required to
call this when done with a ConnectionPool, since
connections are guaranteed to be closed when
garbage collected. But this method gives more control
regarding when the connections are closed.
closeConnections
private void closeConnections(java.util.Vector connections)
toString
public java.lang.String toString()
- Description copied from class:
java.lang.Object
- Convert this Object to a human-readable String.
There are no limits placed on how long this String
should be or what it should contain. We suggest you
make it as intuitive as possible to be able to place
it into System.out.println() 55
and such.
It is typical, but not required, to ensure that this method
never completes abruptly with a java.lang.RuntimeException.
This method will be called when performing string
concatenation with this object. If the result is
null, string concatenation will instead
use "null".
The default implementation returns
getClass().getName() + "@" +
Integer.toHexString(hashCode()).