bean 遇到非应用程序异常;嵌套异常是:org.hibernate.exception.JDBCConnectionException:无法执行查询
The bean encountered a non-application exception; nested exception is: org.hibernate.exception.JDBCConnectionException: could not execute query
我有时会遇到以下异常:
ERROR : 07.16.2021:0709 (05.988) [[]http-nio-8080-exec-4] ShippingSatelliteForm: /addLeadTimeForShippingBakeries.xhtml, user - The bean encountered a non-application exception; nested exception is: ERROR : 07.16.2021:0709 (05.988) [[]http-nio-8080-exec-4] ShippingSatelliteForm: /addLeadTimeForShippingBakeries.xhtml, user - The bean encountered a non-application exception; nested exception is: org.hibernate.exception.JDBCConnectionException: could not execute query
Caused by: com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2030][11211][4.21.29] A communication error occurred during operations on the connection's underlying socket, socket input stream, Caused by: com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2030][11211][4.21.29] A communication error occurred during operations on the connection's underlying socket, socket input stream, or socket output stream. Error location: Reply.fill() - insufficient data (-1). Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001
我已经在 Azure Kubernetes 中部署了应用程序,而 DB2 在本地 - 这是否是由于不同的网络造成的?
这里是猜测,但我会尝试添加 hibernate.c3p0.max_idle_time=300
让连接池每 5 分钟回收一次连接。这可以防止连接存活足够长的时间以致于其他人(数据库、防火墙等)决定终止它...
尝试测试在以下时间后您是否仍然可以使用空闲连接:
- 15 秒
- 30 秒
- 60 秒
等等
很可能您使用了某种 NAT 路由、虚拟(覆盖)网络、负载平衡器等,它们会删除空闲连接以避免 运行内存不足。
如果您每秒 运行 多次查询,连接池对于实现良好的性能很重要,但是如果您不需要连接很多秒,您可以:
- 关闭连接
- 重新测试是否仍然有效
- 配置 TCP Keep-Alive(在服务器端或客户端)
默认 TCP Keep-Alive 设置取决于 OS 配置,并且通常需要启用和设置正确的频率,因为默认频率通常会延迟以避免超时。从 Java 设置这些最近才变得实用,DB2 驱动程序可能还不支持。
参见:How to set socket option (TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL) in java or netty?
但是您的应用程序应该为各种麻烦做好准备,因为:https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing所以您可能想要添加某种重试逻辑来处理现在或将来可能出现的任何类型的网络问题未来。
我有时会遇到以下异常:
ERROR : 07.16.2021:0709 (05.988) [[]http-nio-8080-exec-4] ShippingSatelliteForm: /addLeadTimeForShippingBakeries.xhtml, user - The bean encountered a non-application exception; nested exception is: ERROR : 07.16.2021:0709 (05.988) [[]http-nio-8080-exec-4] ShippingSatelliteForm: /addLeadTimeForShippingBakeries.xhtml, user - The bean encountered a non-application exception; nested exception is: org.hibernate.exception.JDBCConnectionException: could not execute query
Caused by: com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2030][11211][4.21.29] A communication error occurred during operations on the connection's underlying socket, socket input stream, Caused by: com.ibm.db2.jcc.am.DisconnectNonTransientConnectionException: [jcc][t4][2030][11211][4.21.29] A communication error occurred during operations on the connection's underlying socket, socket input stream, or socket output stream. Error location: Reply.fill() - insufficient data (-1). Message: Insufficient data. ERRORCODE=-4499, SQLSTATE=08001
我已经在 Azure Kubernetes 中部署了应用程序,而 DB2 在本地 - 这是否是由于不同的网络造成的?
这里是猜测,但我会尝试添加 hibernate.c3p0.max_idle_time=300
让连接池每 5 分钟回收一次连接。这可以防止连接存活足够长的时间以致于其他人(数据库、防火墙等)决定终止它...
尝试测试在以下时间后您是否仍然可以使用空闲连接:
- 15 秒
- 30 秒
- 60 秒
等等
很可能您使用了某种 NAT 路由、虚拟(覆盖)网络、负载平衡器等,它们会删除空闲连接以避免 运行内存不足。
如果您每秒 运行 多次查询,连接池对于实现良好的性能很重要,但是如果您不需要连接很多秒,您可以:
- 关闭连接
- 重新测试是否仍然有效
- 配置 TCP Keep-Alive(在服务器端或客户端)
默认 TCP Keep-Alive 设置取决于 OS 配置,并且通常需要启用和设置正确的频率,因为默认频率通常会延迟以避免超时。从 Java 设置这些最近才变得实用,DB2 驱动程序可能还不支持。
参见:How to set socket option (TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL) in java or netty?
但是您的应用程序应该为各种麻烦做好准备,因为:https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing所以您可能想要添加某种重试逻辑来处理现在或将来可能出现的任何类型的网络问题未来。