Tomcat: see which streams use the database connection pool

Tomcat has a database connection pool (DBCP) for faster query execution.

In my application, too many connections have been used for too long, I suspect a leak (the connection does not close properly), and I need to find out where the leak is.

QUESTION: How do I find out the name of each thread using a connection?

It is advisable to live a JMX MBean, but other tips are also welcome. Displaying each trace of the thread stack or class name would be acceptable.

Note. I am not looking for an MBean that shows DBCP settings. I want to see what each connection uses.

+4
source share
2 answers

Such a bean, unfortunately, does not exist.

What you can do is enable the logAbandoned parameter in your DBCP configuration. See the documentation for Apache Commons-DBCP ( http://commons.apache.org/dbcp/configuration.html ) for more information: you can use all the configuration options there in your <Resource> element in Tomcat.

logAbandoned will tell you where the connection was retrieved from a pool that was not returned in a timely manner. This may indicate a connection leak or just long requests.

UPDATE 2015-12-15

With Tomcat tomcat-pool you can attach interceptors like SlowQueryReport or, to receive notifications via JMX, SlowQueryReportJmx

These tools may work better than the simpler information you can get from Apache Commons-DBCP.

+8
source

Responding to Christopher, I created a tool to monitor loan / issue connections:

https://github.com/nicolas-raoul/Commons-DBCP-monitoring

It controls the use of the Commons DBCP database and allows you to create the following graphs:

enter image description here

enter image description here

It is very easy to determine which threads hold connections for a long time.

+7
source

All Articles