Hi,

I'm trying to understand the behavior of DBCP a bit better in our Tomcat 4.0 
application.  I am seeing three things that I'm having trouble understanding, and I 
wonder if anybody else has run across these:

1.  I wrapped some timing code around the specific lines of code which retrieve a 
connection from the pool in order to see how long it takes to obtain a connection 
under various load conditions and pool sizes.  The code looks like this:

start = new java.util.Date();
Connection c;
try {
     c = dataSource.getConnection();
} catch (SQLException e) {
     e.printStackTrace();
     throw new BaseException(e);
}
end = new java.util.Date();
System.out.println(new StringBuffer(GET_CON).append(end.getTime() - start.getTime()));

(GET_CON is just a static String which is easy to grep for in catalina.out).

We have maxWait set to 5000, which means throw an exception if we can't get a 
connection from the pool in 5 seconds, right?  And yet I regularly see trace in 
catalina.out indicating that it has taken 10, 20 or 30 seconds to obtain a connection. 
 Does maxWait work as advertised?  If so, what am I doing/seeing wrong?

2.  To trace which particular connections are being retrieved/returned, I also wrapped 
trace code around getConnection() and the places in the application where we close() 
these connections.  The code looks like this:

c.close();
System.out.println(new StringBuffer(CLOSE_CON).append(c.toString()));

c.toString() returns something like org.apache.commons.dbcp.PoolableConnection@987197.

Is it correct that examining this output will tell you which specific connections are 
being retrieved/returned?  In other words, does the substring after "@" -- "@987197" 
in the above example -- uniquely identify a particular connection?

If so, then I am seeing the pool retrieve and return the same connection over and over 
again.  It never varies, even though the pool size is set to 50, the database is 
actually firing up 30 or 40 connections, and the site is under heavy load.  So how do 
I interpret that?

3.  From time to time I see this error in the logs:

DBCP borrowObject failed: null

I've had a look at the DBCP source code, and "null" corresponds to "e.getMessage()" 
for an error that's being thrown as the pool tries to retrieve a particular 
connection.  It's not the "no free connections" error; that has its own catch clause.

In passing, I note that this error seems to be correlated with connections that take a 
long time to retrieve according to the timing trace in #1 above.

Does anybody else get this error?  Have you figured out what it means?

Thanks in advance,

Jerry Gaines

Reply via email to