首页 > 解决方案 > 数据库连接已经耗尽,而 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)

任何输入都受到高度赞赏。谢谢。

标签: javasqloraclehibernatestored-procedures

解决方案


我们找到了问题的根本原因。

db 过程中的 While 循环不会让原始异常抛出给应用程序。一旦这个循环被删除,异常就会被捕获。

Caused by: java.sql.SQLException: ORA-01427: single-row subquery returns more than one row

在更新命令中指定的内部查询返回 2 行,而预期只有 1 行。查询已经更新了更多的约束,它工作得很好。此外,删除了这个不必要的 while 循环。


推荐阅读