java - 当 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&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 小时。这有助于推断什么吗?
解决方案
推荐阅读
- string - 共享首选项 Flutter 中的布尔值列表
- javascript - 我如何返回 paypal-preapproval 的响应?
- typescript - 打字稿默认通用类型
- office-scripts - 在 Visual Studio Code 中编辑 Office 脚本
- java - 带有 Firestore 的可扩展 RecyclerView。怎么做?
- spring-boot - 我应该如何在客户端请求的格式中制作 Spring Boot Rest API 的返回响应
- css - Swift:WKWebView 中不尊重媒体查询
- debugging - Emacs saveplace save-place-alist to file when kill-buffer: 为什么我会遇到钩子的递归深度问题?
- python-3.x - 如何在弹出窗口中获取元素的 ID 或 xpath 以在 python 中实现自动化
- java - 从 Oracle DB 触发器发出 http 请求时出错 - java.sql.SQLException: ORA-29273: HTTP 请求失败 ORA-12541: TNS:no listener