线程池创建
/**
* 队列用线程
* @return
*/
@Bean(name = "queuePool")
public ThreadPoolExecutor queuePool(){
ThreadPoolExecutor pool = new ThreadPoolExecutor(8, 16,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(200),
new ThreadPoolExecutor.CallerRunsPolicy());
return pool;
}
while 循环线程创建
public AsynCompute{
@Resource(name = "queuePool")
ThreadPoolExecutor executorService;
@PostConstruct
public void process(){
executorService.execute(()->{
while (true&&!executorService.isShutdown()){
//TODO 具体业务
}
});
}
}
注意点:executorService.isShutdown()
判断线程池是否关闭状态
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/243773.html