多线程实现数据批量处理

多线程实现数据批量处理代返回值

Map<String, String> map = new HashMap<>();
ExecutorService executorService = Executors.newFixedThreadPool(20);
        Callable<List<Map<String, String>>> task = null;
        List<Callable<List<Map<String, String>>>> clist = new ArrayList<>();
        for (StudentExcelSchool excelSchool : studentExcelSchool) {
            //添加单个线程
            task = new Callable<List<Map<String, String>>>() {
                @Override
                public List<Map<String, String>> call() throws Exception {
                //处理业务数据
                    List<Map<String, String>> maps = saveStudentBatch(excelSchool, schoolById, loginUser);
                    return maps;
                }
            };
            clist.add(task);
        }
        try {
            List<Future<List<Map<String, String>>>> futures = executorService.invokeAll(clist);
            for (Future<List<Map<String, String>>> future : futures) {
                error.addAll(future.get());
            }
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
            map.put("报错", e.getMessage());
            error.add(map);
        } finally {
        //处理业务数据
            String id = MapUtils.getString(result.getData(), "id");
            if(StringUtil.isNotBlank(id)){
                JsonResult<List<String>> userIdFormSysUserRoleByRoleId = userFeign.findUserIdFormSysUserRoleByRoleId(id);
                if(userIdFormSysUserRoleByRoleId.getData().size() == 0){
                    userFeign.deleteRole(Long.valueOf(id));
                }
            }
            executorService.shutdown();
        }
        return error;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值