直接上代码
//定义空数组
List<AAE03> dataList= new CopyOnWriteArrayList<>();
//分页数
List<Integer> pageNumbers= new ArrayList <>();
//定义计数器
StopWatch stopWatch = new StopWatch("导出所有数据");
//开始计数器
stopWatch.start();
CompletableFuture[] completableFutures = pageNumbers.stream()
.map( indexFirst -> CompletableFuture
.supplyAsync( () -> {
//... 省略分页查询
//分页结果 返回
return collect;
} )
// 合并分页
.whenComplete( (bodyList, throwable) -> {
// 合并分页
if (!ObjectUtils.isEmpty( bodyList )) {
dataList.addAll( bodyList );
}
} ) ).toArray( CompletableFuture[]::new );
//合并线程
CompletableFuture.allOf( completableFutures ).join();
stopWatch.stop();
//结束计数器
log.info( "导出数据计数:\n{}",stopWatch.prettyPrint());