I have a Spring Hibernate application on Tomcat. Connection pool is C3P0
I am rapidly encountering a thread pool maxed out warning from C3P0. Then all requests to the webapp hang.
I am still assuming that somewhere in the code I have missed an @Transaction annotation. I want to debug my code.
Question: Can I access the connection pool via code so I can debug when a connection is released and when it is not released?
UPDATE: Current c3p0 config:
<!-- Hibernate -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="jdbc:postgresql://localhost/ikoda01?useUnicode=true&characterEncoding=utf8" />
<property name="user" value="xxxuser" />
<property name="password" value="xxxxx" />
<property name="acquireIncrement" value="2" />
<property name="minPoolSize" value="3" />
<property name="maxPoolSize" value="50" />
<property name="maxIdleTime" value="600" />
</bean>
Can I access the connection pool via code so I can debug when a connection is released and when it is not released?
You don't even have to code, that's built in. If you configure c3p0 to debug Connection leaks, it will simply print stack traces of the codepaths that checked out the leaked Connections to your logs.
Update:
<property name="unreturnedConnectionTimeout" value="30" />
<property name="debugUnreturnedConnectionStackTraces" value="true" />
The value you should use for unreturnedConnectionTimeout
depends on your application. It should be longer than the longest expected legit use of a Connection, but not the shorter it is, the more quickly you'll get log messages about the leak and the more smoothly your app will work around it. For most web-ish applications, the 30 secs shown above is conservative, clients aren't expected to ever wait around 30 secs for a response, so a timeout safely indicates a Connection leak.