比如我有一个线程池,里面有1w个任务,但是单次只执行5个任务,我想实时获取当前积压的数据,案例如下
ExecutorService executorService = new ThreadPoolExecutor(9, 9,
0, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(), new BasicThreadFactory.Builder().namingPattern("attach-transform-job-%d")
.daemon(true).build());
int i=0;
while (i++<10000){
executorService.execute(()->{
//模拟执行任务
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("执行结束");
});
}