Search code examples
javaspringhibernateconnection-poolingc3p0

c3p0 inactive connection not being culled from connection pool after max wait time


I have an existing app that utilizes Spring 3.0.3, Hibernate 3.6.0 and an Oracle DB.

I've got it set up and running c3p0 but I noticed something strange that I can't really figure out.

This is my Spring set up

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${xxgglom.driver}" />
<property name="jdbcUrl" value="${url}" />
<property name="user" value="${username}" />
<property name="password" value="${password}" />
<property name="minPoolSize" value='5' />
<property name="maxPoolSize" value="40" />
<property name="maxIdleTime" value="240" />
<property name="maxIdleTimeExcessConnections" value="180" />
<property name="maxStatements" value="50" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="false" />
<property name="idleConnectionTestPeriod" value="300" />     

I check the database v$session and I see it creates the 5 connections in the pool. I'll start using the app and it will increase the pool size when needed. So I can tell C3P0 is working from checking the logs. The one issue I'm having is. There are these inactive connections, that are pass the maxIdleTime.

I check their alive times and they're way pass the 240 seconds. I check the database again and they all show inactive but when I look in the logs tell me this.

trace com.mchange.v2.resourcepool.BasicResourcePool@282fafdd [managed: 5, unused: 4, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@5f9f7637)

I'm not sure what's going on exactly but after awhile these idle connections start piling up, and they don't seem to be getting culled from the connection pool. Any suggestions on what to do?


Solution

  • maxIdleTime doesn't guarantee that Connections will be culled at any particular time. As long as each Connection is used at least once every 4 minutes under your config, they won't be culled. If you want to put an unconditional limit on Connections' live-time (I don't know why you would), you can use maxConnectionAge.