c3p0连接管理问题

时间:2010-04-14 00:03:28

标签: c3p0

我正在使用Spring 3.0.2,Hibernate 3.5.0和c3p0 0.9.1.2,当涉及到检索连接和提交事务时,我遇到了大量错误。这是我对c3p0的配置:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${jdbc.driverClassName}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="properties">
        <props>
            <prop key="c3p0.acquireIncrement">5</prop>
            <prop key="c3p0.maxIdleTime">30</prop>
            <prop key="c3p0.idleConnectionTestPeriod">20</prop>
            <prop key="c3p0.maxPoolSize">100</prop>
            <prop key="c3p0.maxStatements">0</prop>
            <prop key="c3p0.minPoolSize">1</prop>
            <prop key="user">${jdbc.username}</prop>
            <prop key="password">${jdbc.password}</prop>
        </props>
    </property>
</bean>

直到最近,我经常遇到这个错误:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.

最近我也得到了这些:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
java.sql.SQLException: Connections could not be acquired from the underlying database!

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

这可能是因为连接正在超时。 checkout idle_test_period设置或使用具有合理默认值的bonecp http://jolbox.com