0

在我的产品服务器上出现异常,但它会在几个小时后自动解决。这个问题的原因可能是什么

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was234747 milliseconds ago.The last packet sent successfully to the server was 234747 milliseconds ago, which  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.

我们已经设置了 autoReconnect=true,从论坛我发现我们需要启用空闲连接测试。请指教

应用程序中是否有任何未关闭的连接会导致此异常?

我们使用 Ibatis,下面是 Ibatisconfig 文件

<transactionManager type="JDBC" commitRequired="true">
    <dataSource type="SIMPLE">
        <property name="JDBC.Driver" value="com.mysql.jdbc.Driver" />
        <property name="JDBC.ConnectionURL"
            value="<URL>?autoReconnect=true" />
        <property name="JDBC.Username" value="<username>" />
        <property name="JDBC.Password" value="<password>" />
        <property name="JDBC.DefaultAutoCommit" value="false" />
        <property name="Pool.TimeToWait" value="100" />
        <property name="Pool.PingQuery" value="select 1" />
        <property name="Pool.PingEnabled" value="true" />
        <property name="Pool.PingConnectionsOlderThan" value="300000" />
        <property name="Pool.PingConnectionsNotUsedFor" value="300000" />
    </dataSource>
</transactionManager>
4

1 回答 1

1

好吧,在我的项目中,我遇到了同样的问题。我们使用 mysql,如果连接空闲 8 小时,则 db 将不可用。我们使用的解决方案是使用 C3P0 连接池。在这里检查一下。 http://www.mchange.com/projects/c3p0/

于 2013-08-02T07:39:36.717 回答