spring boot druid动态多数据源监控集成

当经常有发生连接池满获取不到连接时,可以开启druid监控,在连接都正常关闭的应用中,不应该出现下列警告,如下:

10:53:39.927 [Druid-ConnectionPool-Destroy--877824563] ERROR com.alibaba.druid.pool.DruidDataSource - abandon connection, owner thread: http-nio-8066-exec-8, connected at : 1579574585225, open stackTrace
    at java.lang.Thread.getStackTrace(Thread.java:1161)
    at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1450)
    at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:5059)
    at com.alibaba.druid.filter.FilterAdapter.dataSource_getConnection(FilterAdapter.java:2756)
    at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:5055)
    at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1359)
    at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1351)
    at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:78)
    at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:164)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:86)
    at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:72)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.getConnection(DefaultSqlSession.java:298)
    at com.yidoo.xxx.datasource.DBContextHolder.setTargetDataSource(DBContextHolder.java:74)
    at com.yidoo.xxx.datasource.DBContextHolder.setTargetDataSource(DBContextHolder.java:26)
    at com.yidoo.xxx.datasource.DataSourceAspect.before(DataSourceAspect.java:47)
    at sun.reflect.GeneratedMethodAccessor309.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:609)
    at org.springframework.aop.aspectj.AspectJMethodBeforeAdvice.before(AspectJMethodBeforeAdvice.java:43)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:55)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:47)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:671)
    at com.yidoo.xxx.base.service.ErrorLogServiceImpl$$EnhancerBySpringCGLIB$$68c9d6f3.addSysErrorLog(<generated>)
    at com.yidoo.xxx.base.TaException.saveErrorLog(TaException.java:91)
    at com.yidoo.xxx.base.TaException.<init>(TaException.java:52)
    at com.yidoo.xxx.base.BaseConfig.getConfig(BaseConfig.java:113)
    at com.yidoo.xxx.base.BaseConfig.getConfig(BaseConfig.java:118)
    at com.yidoo.xxx.filter.xss.XssAndSqlHttpServletRequestWrapper.getParameter(XssAndSqlHttpServletRequestWrapper.java:59)
    at com.yidoo.xxx.filter.xss.XssAndSqlHttpServletRequestWrapper.<init>(XssAndSqlHttpServletRequestWrapper.java:37)
    at com.yidoo.xxx.filter.XssFilter.doFilter(XssFilter.java:17)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:84)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:111)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:100)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1506)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:819)
ownerThread current state is WAITING, current stackTrace
    at sun.misc.Unsafe.park(Native Method)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
    at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
    at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:103)
    at org.apache.tomcat.util.threads.TaskQueue.take(TaskQueue.java:31)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:819)
要查看活跃的连接堆栈,需要开启下列选项:dyn.spring.datasources[0].removeAbandoned=true
dyn.spring.datasources[0].removeAbandonedTimeout=600
dyn.spring.datasources[0].logAbandoned=true

按照druid的文档配置对应的fitler,即可同时监控多数据源,包括在sharding jdbc中的数据源。可参考下列:

https://blog.csdn.net/garyond/article/details/80189939

https://blog.csdn.net/qq_38455201/article/details/80769354

https://www.cnblogs.com/qdhxhz/p/10192041.html

这样在发生连接获取不到时就能够找到哪些逻辑没有正常关闭连接。

原文地址:https://www.cnblogs.com/zhjh256/p/11675300.html

时间: 2024-10-30 10:19:19

spring boot druid动态多数据源监控集成的相关文章

spring boot redis 缓存(cache)集成

Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 spring boot 连接Mysql spring boot配置druid连接池连接mysql spring boot集成mybatis(1) spring boot集成mybatis(2) – 使用pagehelper实现分页 spring boot集成mybatis(3) – mybatis ge

Spring Boot 入门(六):集成 treetable 和 zTree 实现树形图

本篇文章是接着Spring Boot 入门(五):集成 AOP 进行日志管理写的,主要集成了树形图,在部门列表或者权限列表中,树形图经常被用上.主要是根据相应的 API 凭借 html 字符串 1.treetable 1 <link href="/plugins/treeTable/themes/default/treeTable.css" rel="stylesheet" type="text/css" /> 2 <scrip

Spring Boot 入门(五):集成 AOP 进行日志管理

本篇文章是接着 Spring boot 入门(四):集成 Shiro 实现登陆认证和权限管理写的,按照前面几篇博客的教程,可以搭建一个简单的项目,主要包含了 Pagehelper+MyBatis 分页查询,Generator 代码自动生成器,Shiro登录及权限管理.本篇博客主要是集成 AOP 进行日志管理 1.导入 jar 包 1 <!-- aop --> 2 <dependency> 3 <groupId>org.springframework.boot</g

Spring Boot 入门(八):集成RabbitMQ消息队列

本片文章续<Spring Boot 入门(七):集成 swagger2>,关于RabbitMQ的介绍请参考<java基础(六):RabbitMQ 入门> 1.增加依赖 1 <!--rabbitMq--> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-amqp</artifac

Spring Boot 入门(七):集成 swagger2

本片文章是基于前一篇写的,<Spring Boot 入门(六):集成 treetable 和 zTree 实现树形图>,本篇主要介绍了spring boot集成swagger2.关于swagger的介绍,自行谷歌.我这里有在网上购买的相关视频资料,有需要可以呼叫我. 1.引入相关依赖 1 <dependency> 2 <groupId>io.springfox</groupId> 3 <artifactId>springfox-swagger2&

Spring Boot 入门(九):集成Quartz定时任务

本片文章续<Spring Boot 入门(八):集成RabbitMQ消息队列>,关于Quartz定时任务请参考<Quartz的基本使用之入门(2.3.0版本)> spring boot实现定时任务,除了集成Quartz外,还可以直接使用scheduler注解.使用1个简单的注解就可以完成,为什么还要较为复杂的集成Quartz呢?这里我简单回答下这2中方式的区别,这也是我在项目中为什么要选择Quartz这种方式. 1.scheduler注解方式,一旦定时任务产生异常,那么此定时任务就

Spring Boot 入门(十一):集成 WebSocket, 实时显示系统日志

以前面的博客为基础,最近一篇为Spring Boot 入门(十):集成Redis哨兵模式,实现Mybatis二级缓存.本篇博客主要介绍了Spring Boot集成 Web Socket进行日志的推送,并实时显示在页面上. 1.导入jar包 第一个jar包是websocket的,第二个jar包是关于环形队列的jar包,本案例是通过本地队列存储日志.有条件的话,最好通过中间件存储(eg:redis,mq……).通过本地队列存储日志会存在日志丢失的情况,且日志量太大,会把页面卡死. 1 <!--beg

Spring Boot+Druid进行监控

Druid Spring Boot Spring Boot使用Druid监控 maven配置 applicationproperties配置 方式一原生的servlet和filter方式 方式二使用代码注册Servlet和Filter 项目监控 Druid Druid:一款为监控而生的数据库连接池框架,整个项目由数据库连接池.插件框架和SQL解析器组成. Druid功能介于PowerDrill和Dremel之间,它几乎实现了Dremel的所有功能,并且从PowerDrill吸收一些有趣的数据格式

Spring Boot Quartz 动态配置,持久化

Quartz 是一个很强大的任务调度框架在SpringBoot中也很容易集成 添加依赖: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <!--Quartz--> <dependency> <groupId>org.sp