You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Eslam M. Abbass" <Es...@itworx.com> on 2005/10/06 12:53:33 UTC
Am I configuring my connection pool right?
Hi all-
I need to make sure that am I configuring my connection pool
right?
Here is my class that generates the connection to the needed DAO
private static GenericObjectPool connectionPool = null;
private static ConnectionFactory connectionFactory = null;
private static PoolableConnectionFactory poolableConnectionFactory =
null;
private static PoolingDriver driver = null;
static
{
try
{
String userName = username;
String password = password;
String connectURI = jdbc:oracle:thin:@10.30.0.190:1521:test;
String driverClass =oracle.jdbc.driver.OracleDriver;
int maxActiveConnections = 50;
long maxWaitTime = 10;
Class.forName(driverClass);
connectionPool = new GenericObjectPool(null);
connectionPool.setMaxActive(maxActiveConnections);
connectionPool.setMaxWait(maxWaitTime);
connectionFactory = new
DriverManagerConnectionFactory(connectURI,
userName, password);
poolableConnectionFactory = new PoolableConnectionFactory(
connectionFactory, connectionPool, null, null,
false, true);
Class.forName("org.apache.commons.dbcp.PoolingDriver");
driver = (PoolingDriver) DriverManager
.getDriver("jdbc:apache:commons:dbcp:");
driver.registerPool("example", connectionPool);
}
catch (ClassNotFoundException exception)
{
Logging
.getLogger()
.fatal(
exception.getMessage()
+ " from DatabaseUtility while
intialize the oracle driver");
}
catch (SQLException exception)
{
Logging.getLogger().fatal(
exception.getMessage() + " from
BaseDAO.getConnection()");
}
/**
* getPooledConnection-- Method to return the pooled connection and
read it
* once from the main.properties file
*
* @return Connection
*/
public static Connection getPooledConnection() throws SQLException
{
Connection connection = DriverManager
.getConnection("jdbc:apache:commons:dbcp:example");
printDriverStats();
return connection;
// return new PoolableConnection(connection, connectionPool);
}
Can any one guide me is this how we can make connection pooling and how
can I test that the connection is pooled and destroyed etc.
Best regards,
Eslam M.Abbass
Team Leader
ITWorx Egypt
www.itworx.com