JDK线程池的配置
@Configuration
public class AppConfig {
@Bean
public ThreadPoolExecutor businessPoolExecutor(){
//创建线程池的方式
//使用Executor 创建=>不推荐
//不推荐的原因,里面使用的工作队列是LinkedBlockingQueue,
// 里面默认的长度几乎无限大,会造成核心线程过载,非核心线程不进行加载,最后内存溢出
//2使用 new ThreadPooleExecution对象=>推荐
return new ThreadPoolExecutor(10,50,10, TimeUnit.MILLISECONDS,new LinkedBlockingDeque<>(100));
}
}
调用方法实现异步查询
//注入ThreadPoolExecutor
private final ThreadPoolExecutor threadPoolExecutor;
public DestinationServiceImpl( ThreadPoolExecutor threadPoolExecutor) {
this.threadPoolExecutor = threadPoolExecutor;
}
threadPoolExecutor.execute(() ->{
//将他们的id作为父id进行查询,使用last方法进行分页查询
List<Destination> children = list(new QueryWrapper<Destination>().in("id", 1).last("limit 10"));