2

Spring JDBCTemplateを使用してApacheCommonsデータソース(org.apache.commons.dbcp.BasicDataSource)でSQL操作を実行していますが、サービスが長時間稼働していると、次の例外が発生します。

org.springframework.dao.RecoverableDataAccessException: StatementCallback; SQL [SELECT * FROM vendor ORDER BY name]; The last packet successfully received from the server was 64,206,061 milliseconds ago.  The last packet sent successfully to the server was 64,206,062 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 64,206,061 milliseconds ago.  The last packet sent successfully to the server was 64,206,062 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:406)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:455)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:463)
    at com.cable.comcast.neto.nse.taac.dao.VendorDao.getAllVendor(VendorDao.java:25)
    at com.cable.comcast.neto.nse.taac.controller.RemoteVendorAccessController.requestAccess(RemoteVendorAccessController.java:78)

'autoReconnect = true'を接続文字列に追加しようとしましたが、この問題は引き続き発生します。再接続を管理するために使用できる別のデータソースはありますか?

4

2 に答える 2

1

BasicDataSource は、接続の維持を管理できます。次のプロパティを設定する必要があります。

minEvictableIdleTimeMillis = 120000 // Two minutes
testOnBorrow = true
timeBetweenEvictionRunsMillis = 120000 // Two minutes
minIdle = (some acceptable number of idle connections for your server)

これらは、接続を継続的にテストし、古くなった場合は期限切れにして削除するようにデータ ソースを構成します。接続プーリングのパフォーマンスを微調整するためにチェックインすることを検討したい基本的なデータ ソースには、他にも多くのプロパティがあります。過去に、データベースへのアクセスに問題があり、接続プールの構成方法に問題があったという奇妙な問題に遭遇しました。

于 2010-11-19T00:25:48.923 に答える
0

C3PO を試すことができます:

http://sourceforge.net/projects/c3p0/

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close">
   <property name="user" value="${db.username}"/>
   <property name="password" value="${db.password}"/>
   <property name="driverClass" value="${db.driverClassName}"/>
   <property name="jdbcUrl" value="${db.url}"/>
   <property name="initialPoolSize" value="0"/>
   <property name="maxPoolSize" value="1"/>
   <property name="minPoolSize" value="1"/>
   <property name="acquireIncrement" value="1"/>
   <property name="acquireRetryAttempts" value="0"/>
   <property name="idleConnectionTestPeriod" value="600"/> <!--in seconds-->
</bean>

グレッティングス・パコヴル

于 2010-09-21T14:13:11.527 に答える