Druid连接池连接泄露问题

匿名 (未验证) 提交于 2019-12-02 22:59:29
版权声明: https://blog.csdn.net/yt_1999/article/details/80251919

 2018-05-08 21:33:11.582  WARN --- [pool-4-thread-1] c.alibaba.druid.pool.DruidDataSource : not full timeout retry : 1 2018-05-08 21:33:12.187 ERROR --- [pool-4-thread-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:  ### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 600, active 0, maxActive 250 ### The error may exist in mybatisMapper/TagBack.xml ### The error may involve demo.mapper.TagBackMapper.getValidTags ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 600, active 0, maxActive 250 	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76) 	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) 	at com.sun.proxy.$Proxy51.selectList(Unknown Source) 	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:205) 	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:122) 	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:64) 	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) 	at com.sun.proxy.$Proxy73.getValidTags(Unknown Source) 	at demo.service.ImportDataService.begin(ImportDataService.java:51) 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 	at java.lang.reflect.Method.invoke(Method.java:606) 	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) 	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 	at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.ibatis.exceptions.PersistenceException:  ### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 600, active 0, maxActive 250 ### The error may exist in mybatisMapper/TagBack.xml ### The error may involve demo.mapper.TagBackMapper.getValidTags ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 600, active 0, maxActive 250 	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) 	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122) 	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113) 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 	at java.lang.reflect.Method.invoke(Method.java:606) 	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386) 	... 20 common frames omitted Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 600, active 0, maxActive 250 	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) 	at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82) 	at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68) 	at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:315) 	at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:75) 	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:61) 	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303) 	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154) 	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102) 	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82) 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 	at java.lang.reflect.Method.invoke(Method.java:606) 	at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) 	at com.github.pagehelper.SqlUtil._processPage(SqlUtil.java:351) 	at com.github.pagehelper.SqlUtil.processPage(SqlUtil.java:329) 	at com.github.pagehelper.PageHelper.intercept(PageHelper.java:150) 	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) 	at com.sun.proxy.$Proxy83.query(Unknown Source) 	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120) 	... 26 common frames omitted Caused by: com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 600, active 0, maxActive 250 	at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1190) 	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1012) 	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544) 	at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:662) 	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540) 	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:990) 	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:982) 	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:102) 	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) 	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) 	... 46 common frames omitted

问题描述的是:在执行TagBack.xml中getValidTags语句时,获取连接超时。

为了排查连接为什么会超时,以及哪里没有释放连接

修改properties配置文件

 spring.datasource.removeAbandoned=true #是否开启超时自动回收连接 spring.datasource.removeAbandonedTimeout=180 #设置自动回收连接的超时时间 spring.datasource.logAbandoned=true #打印回收连接时的错误日志

还在后续观察中。未完待续,希望有更多的小伙伴一同讨论,相互学习!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!