Tomcat has a database connection pool (DBCP) to make requests faster.
In my app, too many connections are being used for too long, I suspect a leak (connection not being properly closed) and I need to find out where is the leak.
QUESTION: How to find out the name of each thread which is using a connection?
Preferably live JMX MBean, but other tips are welcome too. Showing each thread's stack trace or class name would be acceptable too.
Note: I am not looking for an MBean that shows the DBCP settings. I want to see what uses each connection.
Tipped by Christopher's answer, I created a tool to monitor borrowed/released connections:
https://github.com/nicolas-raoul/Commons-DBCP-monitoring
It monitors Commons DBCP usage and allows one to create such graphs:
It makes it super easy to identify which threads are holding connections for a long time.
Such a bean unfortunately does not exist.
What you can do is enable the logAbandoned
setting in your DBCP configuration. Look at the documentation for Apache Commons-DBCP ( http://commons.apache.org/dbcp/configuration.html) for details: you can use all of the configuration options there in your <Resource>
element in Tomcat.
logAbandoned
will tell you where a Connection was checked-out of the pool that wasn't returned in a timely way. That can indicate a Connection leak, or just queries that are long-running.
UPDATE 2015-12-15
With Tomcat's tomcat-pool
, you can attach interceptors such as the SlowQueryReport or, to get notifications via JMX, SlowQueryReportJmx
These tools might be able to do a better job than the more basic information you can get back from Apache Commons-DBCP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With