1.配置多线程
private @NotNull List<Map<String, Object>> getData(SysRule rule) throws InterruptedException, ExecutionException {
int pageSize = 200; // 每页查询的数量
int threadPoolSize = Runtime.getRuntime().availableProcessors(); // 根据CPU核心数确定线程池大小
PageQueryExecutor executor = new PageQueryExecutor(threadPoolSize);
int currentPage = 1;
boolean hasMorePages = true;
List<Map<String, Object>> data = new ArrayList<>();
while (hasMorePages) {
log.info("当前页数:" + currentPage);
List<PageQueryTask> tasks = new ArrayList<>();
for (int i = 0; i < threadPoolSize; i++) {
tasks.add(new PageQueryTask(rule.getValue(), pageSize, currentPage));
currentPage++;
}
List<Future<List<Map<String, Object>>>> futures = executor.executeQueries(tasks);
f

最低0.47元/天 解锁文章
1714

被折叠的 条评论
为什么被折叠?



