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();
System.out.println("提交任务数"+threadPoolExecutor.getTaskCount());
System.out.println("完成任务数"+threadPoolExecutor.getCompletedTaskCount() );
System.out.println("当前有"+threadPoolExecutor.getActiveCount()+"个线程正在处理任务");
System.out.println("还剩"+threadPoolExecutor.getQueue().size()+"个任务");
map.put("提交任务数-->",threadPoolExecutor.getTaskCount());
map.put("完成任务数-->",threadPoolExecutor.getCompletedTaskCount());
map.put("当前有多少线程正在处理任务-->",threadPoolExecutor.getActiveCount());
map.put("还剩多少个任务未执行-->",threadPoolExecutor.getQueue().size());
map.put("当前可用队列长度-->",threadPoolExecutor.getQueue().remainingCapacity());
map.put("当前时间-->", DateUtil.getCurrentDate());
}
return map;
}