/** * 线程池. */ private ExecutorService executor = new ThreadPoolExecutor(200, 2000, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new CustomizableThreadFactory("QueryControllerPollThread-"), new ThreadPoolExecutor.DiscardPolicy());
/** * 队列状态. * * @return * @throws SchedulerException */ @RequestMapping(value = "/getPoolStatus", method = RequestMethod.GET, produces = "text/html;charset=UTF-8") @ResponseBody public String getPoolStatus(HttpServletRequest request) {
ThreadPoolExecutor jobExecutor = (ThreadPoolExecutor) executor;
// 线程池状态 StringBuilder html = new StringBuilder(); html.append("池最小:").append(jobExecutor.getCorePoolSize()).append("<br>"); html.append("池最大:").append(jobExecutor.getMaximumPoolSize()).append("<br>"); html.append("池当前大小:").append(jobExecutor.getPoolSize()).append("<br>"); html.append("活动线程:").append(jobExecutor.getActiveCount()).append("<br>"); html.append("历史峰值:").append(jobExecutor.getLargestPoolSize()).append("<br>"); html.append("执行任务数量:").append(jobExecutor.getTaskCount()).append("<br>"); html.append("完成任务数量:").append(jobExecutor.getCompletedTaskCount()).append("<br>"); html.append("队列大小:").append(jobExecutor.getQueue().size()).append("<br>");
return html.toString(); }
|