Future和线程池的结合使用

        // 分组
        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;

你可能感兴趣的:(笔记,java,数据库,前端)