Project

General

Profile

Debugging C3P0 Connections

This page describes a quick method to debug connections from the c3p0 connection pool which may not be closed resulting in the application hanging due to the fact that the number of connections in the pool have reached the maximum size.

This can be done by creating a c3po.properties file at the root of the classpath with the following properties

c3p0.debugUnreturnedConnectionStackTraces=true
c3p0.unreturnedConnectionTimeout=10

the logging level of com.mchange.v2 must be set to INFO, e.g.:

log4j.logger.com.mchange.v2=INFO

Quoting the original documentation at http://www.mchange.com/projects/c3p0/index.html#configuring_to_debug_and_workaround_broken_clients,

unreturnedConnectionTimeout defines a limit (in seconds) to how long a Connection may remain checked out. If set to a nozero value, unreturned, checked-out Connections that exceed this limit will be summarily destroyed, and then replaced in the pool. Obviously, you must take care to set this parameter to a value large enough that all intended operations on checked out Connections have time to complete. You can use this parameter to merely workaround unreliable client apps that fail to close() Connections.

Much better than working-around is fixing. If, in addition to setting unreturnedConnectionTimeout, you set debugUnreturnedConnectionStackTraces to true, then a stack trace will be captured each time a Connection is checked-out. Whenever an unreturned Connection times out, that stack trace will be printed, revealing where a Connection was checked out that was not checked in promptly. debugUnreturnedConnectionStackTraces is intended to be used only for debugging, as capturing a stack trace can slow down Connection check-out."

These settings should not be used for production

Add picture from clipboard (Maximum size: 40 MB)