springboot线程池监控
@RestController
@RequestMapping("test/")
public class TestController {
@Autowired
private Executor taskExecutor;
//这里我们可以通过接口实时观看效果 具体效果如下图
@GetMapping("order/asyncExceutor")
public Map getThreadInfo() {
Map map =new HashMap();
Object[] myThread = {taskExecutor};
for (Object thread : myThread) {
map.put("提交任务数-->",threadPoolExecutor.getTaskCount());
map.put("完成任务数-->",threadPoolExecutor.getCompletedTaskCount());
map.put("当前有多少线程正在处理任务-->",threadPoolExecutor.getActiveCount());
map.put("还剩多少个任务未执行-->",threadPoolExecutor.getQueue().size());
map.put("当前可用队列长度-->",threadPoolExecutor.getQueue().remainingCapacity());
map.put("当前时间-->",DateFormatUtil.stringDate());
}
return map;
}
}