极光推送的的栗子

 // 比赛结束的推送消息
    @Override
    public void sendMessageForGameOver(String gameId) {

        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(100);  //设置此线程等待10分钟
        fixedThreadPool.execute(new MessageForGameOver(gameId));
    }

    class MessageForGameOver implements Runnable {
        private String  gameId;
        public MessageForGameOver(String  gameId) {
            this.gameId = gameId;
        }
        public void startEvent(){
            try{
                //获取主队的所有球员的Id
                Game gameOverDto=gameService.getGameRaw(gameId);
                String homeTeamId = gameOverDto.getHomeTeamId();
                List<String> homeTeamUserIds = getUserIdsByTeamId(homeTeamId);
                //获取客队的所有球员的Id
                String guestTeamId = gameOverDto.getGuestTeamId();
                List<String> guestTeamUserIds = getUserIdsByTeamId(guestTeamId);

                PushMessageDto homeTeamDto = genPushMessageDtoService.genPushMessageDtoForGameOver(gameOverDto, homeTeamUserIds, gameOverDto.getGuestTeamId());
                PushMessageDto guestTeamDto = genPushMessageDtoService.genPushMessageDtoForGameOver(gameOverDto, guestTeamUserIds, gameOverDto.getHomeTeamId());
                PushMessage pushMessage = new PushMessage();
                pushMessage.setBizid(gameId);
                pushMessage.setBiztype(2);
                pushMessage.setProcessStatus(2);
                pushMessage.setProcessCount(0);
                pushMessage.setCreatedTime(new Date());
                pushMessage.setUpdatedTime(new Date());
                PushMessage message = pushMessageService.insertSelective(pushMessage);

                saveMessageDetailService.saveMessageDetailForGameOver(gameOverDto);
                sendMessageToJpush(homeTeamDto, guestTeamDto, message);
            }catch (Exception e){
                log.error("消息发送出错"+e.getMessage());
            }
        }

        @Override
        public void run() {
            try {
                Thread.sleep(10*60*1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            startEvent();
        }
    }

  

posted @ 2016-09-29 15:56  慕容哲别--  阅读(128)  评论(0编辑  收藏  举报