futureTask使用

   List taskList = new ArrayList<>();
            if (leaderList != null && !leaderList.isEmpty()) {
                leaderList.forEach(userId -> {
                    FutureTask future = new FutureTask(() -> {
                        UserInfoVO userInfoVO = vipCenterService.getUserInfoById(userId);
                        if (userInfoVO != null) {
                            req.setUserId(userId);
                            AprilLeaderPrizeDto aprilLeaderPrizeDto = iAprilLeaderPrizeService.querySometimeleaderPricze(req);
                            String phoneNuber = userInfoVO.getPhoneNumber();
                            count.addAndGet(1);
                            String message = mrytConfig.getConfig("");
                            if (StringUtil.isNotBlank(message)) {
                                message = String.format(message, month, month, day, aprilLeaderPrizeDto.getLastTotalMoney(), aprilLeaderPrizeDto.getLastAllvipNumber());
                                activityUtil.sendSms(phoneNuber,message, MessageSignEnum.sign_sxws);
                            }
                            logger.info("SendSaleMessageToLeaderJob---2---phoneNuber:{},message:{},count:{}", phoneNuber, message, count);
                        }
                        return null;
                    });
                    service.submit(future);
                    taskList.add(future);
                });
                for (FutureTask task : taskList) {
                    try {
                        task.get();
                    } catch (Exception e) {
                        logger.error("SendSaleMessageToLeaderJob并行执行报错-{}", e);
                    }
                }
                logger.info("SendSaleMessageToLeaderJob执行结束cost:{}ms,count:{}", System.currentTimeMillis() - start, count);
            }

 

你可能感兴趣的:(java)