The parameter unreturnedConnectionTimeout
times out unreturned connections after a given period of time. I'm trying to decide whether I should use this in my production persistence.xml
? A big plus of using this is that the Connection Pool will be able to recover from leaky connections. A big minus is that leaky connections will be very difficult to detect.
Should I use unreturnedConnectionTimeout
in production applications? If yes, what should its value be? Are there any other pros/cons I should consider?
c3p0 is a Java library that provides a convenient way for managing database connections. In short, it achieves this by creating a pool of connections. It also effectively handles the cleanup of Statements and ResultSets after use.
Hibernate's own connection pooling algorithm is however quite rudimentary. It is intended to help you get started and is not intended for use in a production system or even for performance testing. You should use a third party pool for best performance and stability.
According to C3P0 documentation, 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.
Connection Pooling with the c3p0 Libraryc3p0 is an easy-to-use library for making traditional JDBC drivers “enterprise-ready” by augmenting them with functionality defined by the jdbc3 spec and the optional extensions to jdbc2. As of version 0.9. 5, c3p0 fully supports the jdbc4 spec.
You should debug your Connection leaks, and then not use unreturnedConnectionTimeout
in production, ideally.
To debug Connection leaks, set both unreturnedConnectionTimeout
and debugUnreturnedConnectionStackTraces
, see http://www.mchange.com/projects/c3p0/#configuring_to_debug_and_workaround_broken_clients (archived here). Then, when you have no more leaks, unset both of these parameters.
You would set unreturnedConnectionTimeout
in production mostly if for some reason you can't debug and fix the application whose Connections are leaking, in which case it's a reasonable workaround to just set unreturnedConnectionTimeout
and let c3p0 clean up what your application forgets to.
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