cancel
Showing results for 
Search instead for 
Did you mean: 
cancel

Stop DB Connection Pool Leaks with Handy Tomcat Debug Modes

929
Views
3
Helpful
1
Comments
Advisor
This blog was generated from CDN blog

Created by: James Shepard on 11-06-2008 05:12:44 PM
If you're using JNDI to connect to your database through Tomcat, then it's possible you've had to deal with database connection pool leaks. Your code tests fine, it's been reviewed, but in load tests or in production your app is unable to acquire database connections, the pool is empty!

Fear not, there are some handy parameters which can be set in your application's XML configuration file (in tomcat/conf/Catalina/YOUR_IP/YOUR_APP.xml):

removeAbandoned: Enables automated monitoring of pooled DB connections, and closes them if they time out. This is a catch-all, which prevents bugs in your code from bringing a system to its knees. If your app fails to close a connection, this will close it after a certain time period.

removeAbandonedTimeout: Sets the timeout value for use with the removeAbandonded parameter.

logAbandoned: Logs stack trace information when a pooled DB connection times out. This is invaluable information which can help you quickly track down the offending lines of code which failed to close the connection.

These helpful parameters are documented here on the Apache Tomcat site, along with many other hints and suggestions.

Posted by Vance
1 Comment
Beginner

We were also facing issue like this in production, and fixed by defining a few properties while defining resource in server.xml file /Tomcat/conf/server.xml 

maxActive="30"

maxIdle="10"

maxWait='5000'

validationQuery="SELECT getDate()"

poolPreparedStatements="true"

And then close the connection properly in finally blog of code

finally {

  // Always make sure result sets and statements are closed,

  // and the connection is returned to the pool

  if (rs != null) {

  try { rs.close(); } catch (SQLException e) { ; }

  rs = null;

  }

  if (stmt != null) {

  try { stmt.close(); } catch (SQLException e) { ; }

  stmt = null;

  }

  if (conn != null) {

  try { conn.close(); } catch (SQLException e) { ; }

  conn = null;

  }

References:-

Apache Tomcat 6.0 (6.0.39) - JNDI Datasource HOW-TO

Setting up a JNDI connection pool with Tomcat — GeoServer 2.5.x User Manual

CreatePlease to create content
Content for Community-Ad
August's Community Spotlight Awards
This widget could not be displayed.