// 分组
Collection<Set<Long>> workOrderIdsGroup = WorkOrderShardingUtils.group(workOrderIds);
// mysql
List<Future<List<Long>>> futures = Lists.newArrayListWithExpectedSize(workOrderIdsGroup.size());
for (Set<Long> workOrderIdSet : workOrderIdsGroup) {
Future<List<Long>> submit = taskExecutor
.submit(() -> lotCarMapper.queryIdWithDeleted(workOrderIdSet, timeRangeParams, tenantId));
futures.add(submit);
}
List<Long> result = Lists.newArrayList();
for (Future<List<Long>> future : futures) {
try {
result.addAll(future.get());
} catch (InterruptedException | ExecutionException e) {
log.error("多线程查询批量出现错误", e);
throw new DomainManufactureException("批量查询失败");
}
}
return result;
Future和线程池的结合使用
最新推荐文章于 2024-04-11 00:51:26 发布