一、背景
业务当中多处用到线程池进行异步处理;
为了得知线程池设置是否合理,故需要增加线程池监控;
常见的实现方式:
- org.springframework.scheduling.concurrent.ScheduledExecutorTask
- org.springframework.scheduling.annotation.Scheduled
本文使用1的方式实现,主要是方便进行配置,可以托管多个任务;
二、效果预览
1 | taskName:pool1-monitor. taskCount:820, completedTaskCount:820, largestPoolSize:30, poolSize:30, activeCount:0, corePoolSize:30, maximumPoolSize:50, queueSize:0 |
三、监控逻辑
1 | package com.hisen.thread.monitor.threadpool; |
四、spring xml配置
1 | <!-- ### 线程池监控 开始 ### --> |