All Packages Class Hierarchy This Package Previous Next Index
Class com.sdi.wap.ConnectionPoolManager
java.lang.Object
|
+----com.sdi.wap.ConnectionPoolManager
- public class ConnectionPoolManager
- extends Object
bjc: http://www.WebDevelopersJournal.com/columns/connection_pool.html
This class is a Singleton that provides access to one or many
connection pools defined in a Property file. A client gets
access to the single instance through the static getInstance()
method and can then check-out and check-in connections from a pool.
When the client shuts down it should call the release() method
to close all open connections and do other clean up.
-
clients
-
-
drivers
-
-
instance
-
-
log
-
-
pools
-
-
ConnectionPoolManager()
- A private constructor since this is a Singleton
-
createPools(Properties)
- Creates instances of DBConnectionPool based on the properties.
-
freeConnection(String, Connection)
- Returns a connection to the named pool.
-
freeConnections(String)
- Insert the method's description here.
-
getConnection(String)
- Returns an open connection.
-
getConnection(String, long)
- Returns an open connection.
-
getInstance()
- Returns the single instance, creating one if it's the
first time this method is called.
-
init()
- Loads properties and initializes the instance with its values.
-
loadDrivers(Properties)
- Loads and registers all JDBC drivers.
-
log(String)
- Writes a message to the log file.
-
log(Throwable, String)
- Writes a message with an Exception to the log file.
-
maxConnections(String)
- Insert the method's description here.
-
release()
- Closes all open connections and deregisters all drivers.
-
usedConnections(String)
- Insert the method's description here.
instance
private static ConnectionPoolManager instance
clients
private static int clients
drivers
private Vector drivers
log
private PrintWriter log
pools
private Hashtable pools
ConnectionPoolManager
private ConnectionPoolManager()
- A private constructor since this is a Singleton
createPools
private void createPools(Properties props)
- Creates instances of DBConnectionPool based on the properties.
A DBConnectionPool can be defined with the following properties:
<poolname>.url The JDBC URL for the database
<poolname>.user A database user (optional)
<poolname>.password A database user password (if user specified)
<poolname>.maxconn The maximal number of connections (optional)
- Parameters:
- props - The connection pool properties
freeConnection
public void freeConnection(String name,
Connection con)
- Returns a connection to the named pool.
- Parameters:
- name - The pool name as defined in the properties file
- con - The Connection
freeConnections
public static int freeConnections(String name)
- Insert the method's description here.
Creation date: (02/20/00 20:19:49)
getConnection
public Connection getConnection(String name)
- Returns an open connection. If no one is available, and the max
number of connections has not been reached, a new connection is
created.
- Parameters:
- name - The pool name as defined in the properties file
- Returns:
- Connection The connection or null
getConnection
public Connection getConnection(String name,
long time)
- Returns an open connection. If no one is available, and the max
number of connections has not been reached, a new connection is
created. If the max number has been reached, waits until one
is available or the specified time has elapsed.
- Parameters:
- name - The pool name as defined in the properties file
- time - The number of milliseconds to wait
- Returns:
- Connection The connection or null
getInstance
public static synchronized ConnectionPoolManager getInstance()
- Returns the single instance, creating one if it's the
first time this method is called.
- Returns:
- DBConnectionManager The single instance.
init
private void init()
- Loads properties and initializes the instance with its values.
loadDrivers
private void loadDrivers(Properties props)
- Loads and registers all JDBC drivers. This is done by the
DBConnectionManager, as opposed to the DBConnectionPool,
since many pools may share the same driver.
- Parameters:
- props - The connection pool properties
log
private void log(String msg)
- Writes a message to the log file.
log
private void log(Throwable e,
String msg)
- Writes a message with an Exception to the log file.
maxConnections
public static int maxConnections(String name)
- Insert the method's description here.
Creation date: (02/20/00 20:19:49)
release
public synchronized void release()
- Closes all open connections and deregisters all drivers.
usedConnections
public static int usedConnections(String name)
- Insert the method's description here.
Creation date: (02/20/00 20:19:49)
All Packages Class Hierarchy This Package Previous Next Index