c3p0: what does `maxIdleTime` really mean?

9.4k views Asked by At

in c3p0, maxIdleTime means:

maxIdleTime: (Default: 0) Seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire.

I don't get it. Let's say, if there are 10 awaiting connections in the connection pool, and after maxIdleTime has passed, there are still no new database requests, then all these connections should be discarded? then there will be 0 awaiting connections in the pool?

2

There are 2 answers

2
Steve Waldman On

If there are 10 Connections in the pool and no activity, then after maxIdleTime has passed, yes, they will all be expired.

But that does not mean there will be no Connections left in the pool. At the same time as the pool expires old Connections, it will acquire begin new Connections from the DBMS in order to uphold the minPoolSize configuration parameter.

0
zaarour On

If you have kept a large pool size (i.e. greater than what you anticipate as 99th percentile load), this will mean that you will have lots of idle connections lying around and it is better to clean them up periodically via maxIdleTime and idleConnectionTestPeriod parameter

May be, you will need to add too idleConnectionTestPeriod and preferredTestQuery be sure that connection are valid or not