java springboot 监控线程池的状态
在使用多线程的时候使用接口查看线程数量
·
@Autowired
private Executor personInfoTaskExecutor;
/**
* 监控线程池状态
* @return
*/
@GetMapping("asyncExceutorInfo")
public Map getThreadInfo() {
Map map =new HashMap();
Object[] myThread = {personInfoTaskExecutor};
for (Object thread : myThread) {
ThreadPoolTaskExecutor threadTask = (ThreadPoolTaskExecutor) thread;
ThreadPoolExecutor threadPoolExecutor =threadTask.getThreadPoolExecutor();
map.put("提交任务数-->",threadPoolExecutor.getTaskCount());
map.put("完成任务数-->",threadPoolExecutor.getCompletedTaskCount());
map.put("当前有多少线程正在处理任务-->",threadPoolExecutor.getActiveCount());
map.put("还剩多少个任务未执行-->",threadPoolExecutor.getQueue().size());
map.put("当前可用队列长度-->",threadPoolExecutor.getQueue().remainingCapacity());
}
return map;
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)