Yeah, kind of bites you if you forget to do so in one section of the code :D

Nathan Christiansen wrote:

Sorry. I had a bug in my code.

I had one database call where I was checking parameters and returning without calling Connection.close();

-- Nathan Christiansen
  Tahitian Noni International
  http://www.tahitiannoni.com


-----Original Message-----
From: Nathan Christiansen Sent: Wednesday, September 17, 2003 12:28 PM
To: [EMAIL PROTECTED]
Subject: DBCP and MySQL giving pool exhausted SQLException



When I stress test my web app using JMeter, I am suddenly getting a "DBCP could not obtain an idle db connection, pool exhausted" SQLException thrown.


When I test with 25 simulated users every one of my 25 threads gets the exception after the first 25 requests.

What am I doing wrong?

My setup:

RH Linux 7.1
Java 1.4.1_01
Tomcat 4.1.24
DBCP 1.0

MySQL 3.23.56


My pertinent DBCP configuration:


removeAbandoned = true
maxActive = 25
maxIdle = 10
maxWait = 10000
url ends with ?autoReconnect=true

I double checked that all of my database connections in my code follow the pattern of:

Connection conDBConnection = getConnection();
PreparedStatement psDBStatement = null;
ResultSet rsDBResult = null;
try
{
psDBStatement = conDBConnection.prepareStatement("select query from views where viewid = ?");
psDBStatement.setInt(1, nViewID);
rsDBResult = psDBStatement.executeQuery();
if (rsDBResult.next())
{
strReturnValue = rsDBResult.getString(1);
}
}
catch (SQLException sqle)
{
sqle.printStackTrace();
strReturnValue = null;
}
finally
{
try
{
if (rsDBResult != null) rsDBResult.close();
if (psDBStatement != null) psDBStatement.close();
if (conDBConnection != null) conDBConnection.close();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
}




My getConnection method is:

static DataSource m_dsDataSource = null;

static {
initDataSource("java:comp/env/jdbc/cm/mysql");
}

protected static void initDataSource(String a_strSource)
{
try
{
InitialContext ic = new InitialContext();
m_dsDataSource = (DataSource)ic.lookup(a_strSource);
}
catch(Exception e)
{
e.printStackTrace();
m_dsDataSource = null;
}
}

protected static Connection getConnection()
{
try
{
if (m_dsDataSource != null)
{
return m_dsDataSource.getConnection();
}
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}



-- Nathan Christiansen Tahitian Noni International http://www.tahitiannoni.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]








---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to