Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C3P0: unreturnedConnectionTimeout in production?

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?

like image 204
Monarch Wadia Avatar asked Apr 13 '15 20:04

Monarch Wadia


People also ask

What is the use of c3p0?

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.

Is hibernate pooling algorithm is intended for production 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.

What is unreturnedConnectionTimeout?

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.

How does c3p0 connection pooling work?

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.


1 Answers

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.

like image 181
Steve Waldman Avatar answered Oct 17 '22 06:10

Steve Waldman