java - 数据库连接已经耗尽,而 Weblogic 连接池非常好
问题描述
我遇到了一个典型的问题,其中 WebLogic 连接池容量低于限制,但 Oracle DB 连接不断增加,最终达到最大 DB 连接大小并停止响应。
我们正在使用hibernate调用数据库存储过程来更新数据库中的一些记录。
create or replace procedure UPDATE_TIME
(
p_alarmId NUMBER,
p_clearTime NUMBER
)
is
v_errorCode NUMBER := 1;
begin
while ( v_errorCode != 0 )
loop
v_errorCode := 0;
begin
update ANNOTATION
set PARTITION_TIME=p_clearTime
where ANN_ID = (select ANNOTATION_ID from CORE where ID = p_alarmId) and PARTITION_TIME = 0;
exception
when OTHERS then
v_errorCode := 1;
end;
end loop;
end;
/
最后,WebLogic 事务在 5 分钟后超时,因为如下所述指定了套接字超时,但 DB 连接永远不会空闲。
<url>jdbc:mysql://localhost:31300/oneodb?socketTimeout=300000</url>
例外:
javax.ejb.EJBException: EJB Exception: ; nested exception is:
javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: could not execute native bulk manipulation query
...
at Caused by: oracle.net.ns.NetException: Socket read timed out
at oracle.net.ns.Packet.receive(Packet.java:339)
任何输入都受到高度赞赏。谢谢。
解决方案
我们找到了问题的根本原因。
db 过程中的 While 循环不会让原始异常抛出给应用程序。一旦这个循环被删除,异常就会被捕获。
Caused by: java.sql.SQLException: ORA-01427: single-row subquery returns more than one row
在更新命令中指定的内部查询返回 2 行,而预期只有 1 行。查询已经更新了更多的约束,它工作得很好。此外,删除了这个不必要的 while 循环。
推荐阅读
- discord.py - 防止 jar 文件在 repl.it 上终止
- firebase-authentication - 从 Electron Firebase 应用程序在浏览器中打开登录弹出窗口
- boost - 使用 std::move 作为参数传递的共享 ptr 提升 asio 帖子
- python - Python Selenium - 单击没有下一步按钮的页面
- angular - Angular 11 - 延迟加载路由问题
- javascript - 如何在其他异步函数中调用aysnc函数getAffiliatesCodes()
- python - 如何在python中设置默认工作目录?
- java - 如何在 JAX-WS(Spring Boot + Apache CXF)中返回 400 响应而不是 SOAPFault
- ios - 完整性无法验证
- libreoffice - Libre Office 配置文件 bootstrap.ini 损坏