Search code examples
javatomcatjdbcconnection-pooling

How to monitor where my connections go?


I run some tomcat application, use jndi connection pool. In some time connection pool stops to give connections and application hangs. Seems because some code receives connection and doesn't return it back to the pool. How can I monitor - which code does it ? More common - I want to see what all connections do at the moment.

I cannot change application. But I can adjust Tomcat, maybe add some interceptors.


Solution

  • Most connection pool implementations can be configured to detect connections that are not returned to the pool. E.g. for Tomcat's JDBC connection pool there are various configurations options for "abandoned connections" (connections for which the lease expired). If you search for "Abandoned" on this web-page, you'll find the options:

    • removeAbandoned
    • removeAbandonedTimeout
    • logAbandoned
    • suspectTimeout

    As mentioned on the web-page, these settings will add a little overhead but at least your application will not hang. When testing your application, set a low value for removeAbandonedTimeout and a low value for maxActive so that you can catch unreturned connections early.