2010-04-14 117 views
0

我使用Spring 3.0.2,Hibernate 3.5.0和c3p0 0.9.1.2,並且在檢索連接和提交事務時出現大量錯誤。這裏是我的C3P0的配置: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! 

有什麼建議?

回答

0

這可能是因爲連接超時。檢出idle_test_period設置或使用bonecp http://jolbox.com,它具有合理的默認值。