Professional Documents
Culture Documents
C3P0
C3p0 Connection pools are very easy to configure via the following basic parameters:
acquireIncrement
initialPoolSize
maxPoolSize
maxIdleTime
minPoolSize
maxConnectionAge
maxIdleTime
maxIdleTimeExcessConnections
By default, pools will never expire Connections. If you wish Connections to be expired over time in
order to maintain "freshness", set maxIdleTime and/or maxConnectionAge. maxIdleTime defines
how many seconds a Connection should be permitted to go unused before being removed from the
pool. maxConnectionAge forces the pool to cull any Connections that were acquired from the
database more than the set number of seconds in the past.
maxIdleTimeExcessConnections
pools when the pool is not under load. By default, c3p0 pools grow under load, but only shrink if
Connections fail a Connection test or are expired away via the parameters described above. Some
users want their pools to quickly release unnecessary Connections after a spike in usage that forces
a large pool size. You can achieve this by setting maxIdleTimeExcessConnections to a value much
shorter than maxIdleTime, forcing Connections beyond your set minimum size to be released if
they sit idle for more than a short period of time.
Some general advice about all of these timeout parameters: Slow down! The point of Connection
pooling is to bear the cost of acquiring a Connection only once, and then to reuse the Connection
many, many times. Most databases support Connections that remain open for hours at a time.
There's no need to churn through all your Connections every few seconds or minutes.
Setting maxConnectionAge or maxIdleTime to 1800 (30 minutes) is quite aggressive. For most
databases, several hours may be more appropriate. You can ensure the reliability of your
Connections by testing them, rather than by tossing them. The only one of these parameters that
should generally be set to a few minutes or less is maxIdleTimeExcessConnections.