/** * 新加列表 * * @author [email protected] * @param nqdmList * @since 1.0 */ public synchronized void addList(List<NoticeQueueDM> nqdmList) { if (null != nqdmList && 0 != nqdmList.size()) { for (NoticeQueueDM dm : nqdmList) { this.countMap.put(dm.getId(), 0); dm.setTime(new Date()); dm.setInitTime(new Date()); // this.nqdmList.add(dm); this.nqdmMap.put(dm.getId(), dm); } } }
/** * 8次定时发送发送 * * @author 朱伟亮 */ @Scheduled(cron = "0/1 * * * * ?") public void sending8() { List<NoticeQueueDM> returnList = null; Set<String> removeId = null; try { if (nqdmMap.isEmpty() && countMap.isEmpty()) { } else { log.info("当前队列数:" + nqdmMap.size() + " " + countMap.size()); } now = new Date().getTime(); returnList = new ArrayList<>(); removeId = new HashSet<>(); for (NoticeQueueDM nqdm : nqdmMap.values()) { if (null == nqdm || null == nqdm.getId()) { continue; } Integer value = countMap.get(nqdm.getId()); int count = 0; if (null == value) { countMap.put(nqdm.getId(), new Integer(0)); } else { count = value.intValue(); } if (msIntervals.length <= count || count < 0) { nqdm.setStatus(NoticeStatus.STOP.getValue()); removeId.add(nqdm.getId()); } long send = nqdm.getInitTime().getTime() + msIntervals[count].longValue(); if (now <= send) { continue; } else { boolean isSuccess = send(nqdm); count = count + 1; log.debug("发送处理:" + nqdm.getUrl() + " 发送次数:" + count); countMap.put(nqdm.getId(), count); if (isSuccess) { nqdm.setStatus(NoticeStatus.RECEIVED.getValue()); removeId.add(nqdm.getId()); } else { if (count >= msIntervals.length) { nqdm.setStatus(NoticeStatus.STOP.getValue()); removeId.add(nqdm.getId()); } } nqdm.setTime(new Date()); if (!MONITOR_ID.equals(nqdm.getId())) { returnList.add(nqdm); } } } if (0 < returnList.size()) { noticeBO.sent(returnList); } for (String id : removeId) { nqdmMap.remove(id); countMap.remove(id); } } catch (Exception e) { nqdmMap = Collections.synchronizedMap(new HashMap<String, NoticeQueueDM>()); countMap = Collections.synchronizedMap(new HashMap<String, Integer>()); } }