druid连接不释放问题

dlulp 发布于 2014/11/26 19:30
阅读 21K+
收藏 2

@wenshao 你好,想跟你请教个问题:

1:最近我在用druid做项目时碰到一个问题,应用在访问一段时间后会出现数据连接不响应,应用无响应现象,必须重启才可以继续使用,通过查看监控平台看到逻辑连接打开次数=87,逻辑连接关闭次数为61,两者不相等,连接池中连接数为0,是不是表示泄漏?


   2:我的配置文件如下,版本为1.0.9


3:此时weblogic控制台打印错误如下:

 "[STUCK] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'" waiting for lock java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@1cfa3bae WAITING
          
            sun.misc.Unsafe.park(Native Method)
          
            java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
          
            java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
          
            com.alibaba.druid.pool.DruidDataSource.takeLast(DruidDataSource.java:1348)
          
            com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1023)
          
            com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:898)
          
            com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
          
            com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)
          
            com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
          
            com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:880)
          
            com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)
          
            com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)
          
            org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)

3:应用日志打印如下:

<2014-11-23 下午05时58分51秒 CST> <Error> <WebLogicServer> <BEA-000337> <[STUCK] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)' has been busy for "687" seconds working on the request "weblogic.servlet.internal.ServletRequestImpl@1ddb5485[
POST /CRM_WH/servlet/CommonServlet HTTP/1.1
x-requested-with: XMLHttpRequest
Accept-Language: zh-cn
Referer: http://133.64.103.7:7012/CRM_WH/jsp/procedure/commonProcedureCall.jsp?menue_attr_id=8020
Accept: */*
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0)
Content-Length: 329
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=YgXcJvhJbg3Z7LHvTLhvSyGzhZMnJlN2LnM3LQZ2nZQDyRqfpYyQ!-464481048


]", which is more than the configured time (StuckThreadMaxTime) of "600" seconds. Stack trace:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
com.alibaba.druid.pool.DruidDataSource.takeLast(DruidDataSource.java:1348)
com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1023)
com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:898)
com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)
com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:880)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)
com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)
org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:214)
$Proxy63.prepareStatement(Unknown Source)
sun.reflect.GeneratedMethodAccessor75.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.ibatis.common.jdbc.logging.ConnectionLogProxy.invoke(ConnectionLogProxy.java:53)
$Proxy64.prepareStatement(Unknown Source)
com.ibatis.sqlmap.engine.execution.SqlExecutor.prepareStatement(SqlExecutor.java:497)
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:75)
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteUpdate(MappedStatement.java:216)
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:94)
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:393)
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)
org.springframework.orm.ibatis.SqlMapClientTemplate$8.doInSqlMapClient(SqlMapClientTemplate.java:366)
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
org.springframework.orm.ibatis.SqlMapClientTemplate.insert(SqlMapClientTemplate.java:364)
com.tydic.crm.wh.dao.impl.CommonDaoImpl.insert(CommonDaoImpl.java:120)
sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$Proxy62.insert(Unknown Source)
com.tydic.crm.wh.component.LogInterceptor.doAccessCheck(LogInterceptor.java:59)
sun.reflect.GeneratedMethodAccessor77.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:603)
org.springframework.aop.aspectj.AspectJMethodBeforeAdvice.before(AspectJMethodBeforeAdvice.java:39)
org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:49)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$Proxy62.callProcedure(Unknown Source)
com.tydic.crm.wh.servlet.CommonServlet.doPost(CommonServlet.java:77)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124)
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

5:系统运行一段时间 后出现:

com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 30000, active 20, runningSqlCount 3 :

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:203)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:268)
at com.tydic.crm.wh.dao.impl.CommonDaoImpl.qryMapInfo(CommonDaoImpl.java:28)
at sun.reflect.GeneratedMethodAccessor96.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy62.qryMapInfo(Unknown Source)


6:还有一个问题,如果应用中有些SQL执行时间太长,超过weblogic设置的超时时间(假如60S),进行被回收后,数据库连接是否不会释放,导致泄露?

 以上是我做项目遇到的一些问题,请您帮助,如果有不对的地方还请不吝赐教。

加载中
0
ForEleven
ForEleven
先专注一下,我的应用数据库连接也会出问题,还没找时间排查
0
dlulp
dlulp
没有等到合适的回复,自己顶一下
0
wenshao
wenshao
你应该是有连接打开了没有关闭
dlulp
dlulp
谢谢,找到问题了,确实有个地方我是手动打开的。
0
wenshao
wenshao
https://github.com/alibaba/druid/wiki/%E8%BF%9E%E6%8E%A5%E6%B3%84%E6%BC%8F%E7%9B%91%E6%B5%8B
0
李问问
这个肯定是有connection没有close,你仔细查一下,我也是这样,后来关闭了就好了,两者相等。现在的问题是,我的sqlserver里面用sp_who查看连接时,还是有近200的连接,状态为sleeping,求解!
0
MLGKO
MLGKO

我也遇到同样的问题了,刚开始“逻辑连接打开次数”和“逻辑连接关闭次数”是匹配的 可以过一段时间之后 就不匹配了 在过一段时间“池中连接数(27个)”比“池中连接数峰值(30个)”少(因为我初始化最小连接是30个,最小空闲连接也是30个最大是50个)然后也配置removeAbandoned=true,removeAbandonedTimeout=180,

logAbandoned=true这三个参数了 我发现连接数不匹配的时候也查看了StackTrace for active Connection这个 但是这个里面什么都没有,然后也按照官方的说法“在内置监控页面weburi-detail.html中,查看JdbcPoolConnectionOpenCount和JdbcPoolConnectionCloseCount属性,如果不相等,就是泄漏了。”一个一个查看url的打开链接次数(JdbcPoolConnectionOpenCount)和关闭连接次数(JdbcPoolConnectionCloseCount)都一样 但是为什么还有链接没有释放?removeAbandoned这个属性是不是表示的是我从连接池拿到一个连接没有返回到连接池里面在一定时间内强制回收是吗?

q
qdmdnm
楼主搞定了吗 我也有此问题 监控中看不到
0
AAA袋
AAA袋

druiddatasource某种情况下,比如数据源ip换了,我要如何对象销毁掉不要;后面我再重新创建 ?

返回顶部
顶部