WebLogic 数据源连接泄露

文章讲述了在WebLogic应用开发中遇到的连接泄露问题,涉及SQLException和ResourceLimitException,焦点在于如何识别泄漏的数据库连接,以及如何通过weblogicconsole管理和配置连接池来避免和解决连接泄露,包括自动收集连接泄露信息并设置诊断参数。
摘要由CSDN通过智能技术生成

编码时,有时会忘记释放使用的数据源连接,造成连接泄露,没有连接资源可用。

现象

java.sql.SQLException: Cannot obtain XAConnection
        at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1691)
        at weblogic.jdbc.jta.DataSource.getConnectionInternal(DataSource.java:523)
        at weblogic.jdbc.jta.DataSource.getConnection(DataSource.java:500)
        at weblogic.jdbc.common.internal.WLDataSourceImpl.getConnectionInternal(WLDataSourceImpl.java:631)
        at weblogic.jdbc.common.internal.WLDataSourceImpl.getConnection(WLDataSourceImpl.java:611)
        at weblogic.jdbc.common.internal.WLDataSourceImpl.getConnection(WLDataSourceImpl.java:604)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:108)
        at TastyList.doGet(TastyList.java:46)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:295)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
        at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:353)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:250)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3793)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3763)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:344)
        at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
        at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
        at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
        at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2451)
        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2299)
        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2277)
        at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1720)
        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1680)
        at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:272)
        at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
        at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
        at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
        at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
        at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:655)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:420)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)
Caused by: java.sql.SQLException: weblogic.common.resourcepool.ResourceLimitException: No resources currently available in pool datasourceXA1 to allocate to applications, please increase the size of the pool and retry..
        at weblogic.common.resourcepool.ResourcePoolImpl.reserveResourceInternal(ResourcePoolImpl.java:669)
        at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:378)
        at weblogic.common.resourcepool.ResourcePoolImpl.reserveResource(ResourcePoolImpl.java:365)
        at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:608)
        at weblogic.jdbc.common.internal.ConnectionPool.reserve(ConnectionPool.java:521)
        at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:144)
        at weblogic.jdbc.common.internal.ConnectionPoolManager.reserve(ConnectionPoolManager.java:94)
        at weblogic.jdbc.jta.DataSource.getXAConnectionFromPool(DataSource.java:1938)
        at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1679)
        at weblogic.jdbc.jta.DataSource.getConnectionInternal(DataSource.java:523)
        at weblogic.jdbc.jta.DataSource.getConnection(DataSource.java:500)
        at weblogic.jdbc.common.internal.WLDataSourceImpl.getConnectionInternal(WLDataSourceImpl.java:631)
        at weblogic.jdbc.common.internal.WLDataSourceImpl.getConnection(WLDataSourceImpl.java:611)
        at weblogic.jdbc.common.internal.WLDataSourceImpl.getConnection(WLDataSourceImpl.java:604)
        at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:108)
        at TastyList.doGet(TastyList.java:46)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:295)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
        at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:353)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:250)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3793)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3763)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:344)
        at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
        at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
        at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
        at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2451)
        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2299)
        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2277)
        at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1720)
        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1680)
        at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:272)
        at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
        at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
        at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
        at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
        at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:655)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:420)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)

        at weblogic.jdbc.jta.DataSource.getXAConnectionFromPool(DataSource.java:1982)
        at weblogic.jdbc.jta.DataSource.refreshXAConnAndEnlist(DataSource.java:1679)
        ... 33 more

重点log:
明确那个数据源发生了连接泄露

Caused by: java.sql.SQLException: weblogic.common.resourcepool.ResourceLimitException: No resources currently available in pool xxxx to allocate to applications, please increase the size of the pool and retry.

明确在哪个文件中使用了数据源连接没有释放

at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:108)
at TastyList.doGet(TastyList.java:46) --->使用数据源连接的地方,一般是调用DataSource.getConnection()方法的地方
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)

解决方法

不重启weblogic,让weblogic 自动回收
weblogic console->Services->Data Sources->log中已明确的数据源->Configuration->Connection Pool->Advanced中
在这里插入图片描述
当然最根本的办法是,根据log提示,DataSource.getConnection()后,及时close连接。
例如:
在这里插入图片描述

自动收集连接泄露

weblogic console->Services->Data Sources->数据源->Configuration ->Diagnostics
开启连接泄露的收集以及设定收集间隔时间。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值