首页 > 解决方案 > 当 domain.xml 中的验证为真时,MySQLNonTransientConnectionException/CommunicationsException?

问题描述

设置:Glassfish 3x、Java EE、EclipseLink。

jdbc 连接池配置(来自 domain.xml):

<jdbc-connection-pool validation-table-name="dummy" pool-resize-quantity="5" max-pool-size="300" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" wrap-jdbc-objects="false" res-type="javax.sql.XADataSource" steady-pool-size="25" name="mysql_bazaarify_rootPool" is-connection-validation-required="true" non-transactional-connections="true" validate-atmost-once-period-in-seconds="60">
      <property name="URL" value="jdbc:mysql://demodb.mydb.com:3306/database?zeroDateTimeBehavior=convertToNull&amp;useUnicode=yes"></property>

对于不同的查询,很少获得 CommunicationsException。我已配置为在使用前验证连接,有效期为 60 秒。sql server 上的 wait_time 为 8 小时。

我仍然在我的日志中看到以下错误(每天约 50 次)异常跟踪:

Internal Exception: 
    com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
    Error Code: 0
    ....
    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 
    The last packet successfully received from the server was 56,688,227 milliseconds ago.  
    The last packet sent successfully to the server was 56,688,227 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.
    ....
    Caused by: java.net.SocketException: Connection timed out
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3832)
        ... 140 more

我的问题是,当我设置了要验证的连接(每 60 秒)时,我是否有可能从连接池中获得一个陈旧/断开的连接,这表明与 mysql 的最后一次通信是(> 60 秒)之前?

在从池中返回一个健康的连接之前,不应该验证连接吗?这些异常与我配置的设置是否正常?

PS 我观察到在所有此类故障中,报告的毫秒前值始终> 8 小时。这有助于推断什么吗?

标签: javamysqljdbcglassfishconnection-pooling

解决方案


推荐阅读