I am using c3p0 connection pool with spring (with plain jdbc, NO hibernate). Here is my config

    <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> 
        <property name="driverClass" value="${jdbc.driver}"/> 
        <property name="jdbcUrl" value="${jdbc.url}"/> 
        <property name="user" value="${jdbc.username}"/> 
        <property name="password" value="${jdbc.password}"/> 
        <property name="acquireIncrement" value="3"/> 
        <property name="minPoolSize" value="3"/> 
        <property name="maxPoolSize" value="25"/> 
        <property name="maxStatementsPerConnection" value="0"/> 
        <property name="numHelperThreads" value="6"/>         
        <property name="testConnectionOnCheckout" value="false" /> 
        <property name="testConnectionOnCheckin" value="false" /> 
        <property name="idleConnectionTestPeriod" value="10"/> 
        <property name="preferredTestQuery" value="select curdate()"/> 
    <property name="maxIdleTime" value="5" />    
    <property name="unreturnedConnectionTimeout" value="5" />      
    <property name="debugUnreturnedConnectionStackTraces" value="true" /> 
    </bean> 
 

I do see that connection pool hits max value of 25 connections but there shrinks back never shrinks back when load reduces.

I am missing some config here???

有帮助吗?

解决方案

Please see the config parameters maxIdleTime and maxIdleTimeExcessConnections.

If you want to aggressively pare back pool size when load lightens, set a short maxIdleTimeExcessConnections. Leave just plain maxIdleTime fairly long, so you don't needlessly churn through Connections once your pool has hit minPoolSize.

If you don't care so much, then just set maxIdleTime and eventually the pool will shrink as idle Connections expire. But for reasonable values of maxIdleTime, this will happen slowly.

If neither maxIdleTime nor maxIdleTimeExcessConnections (nor maxConnectionAge) are set, these values all default to zero, meaning Connections never expire, and the pool will only shrink as Connections break and fail tests.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top