public static ThreadPoolExecutor myPool = new ThreadPoolExecutor(5,20,30, TimeUnit.MINUTES,new ArrayBlockingQueue<Runnable>(100));
public void process(){
List<String> empList = new ArrayList<>(1000);
List<CompletableFuture<String>> myFutures = empList.stream()
.map(emp -> CompletableFuture.supplyAsync(() -> doSth(emp), myPool))
.collect(Collectors.toList());
List<String> result = myFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());
}
public String doSth(String emp){
return "abc";
}
线程池使用
最新推荐文章于 2023-01-10 23:39:06 发布