Authored by jack

update

@@ -15,7 +15,9 @@ import org.springframework.stereotype.Service; @@ -15,7 +15,9 @@ import org.springframework.stereotype.Service;
15 15
16 import java.io.UnsupportedEncodingException; 16 import java.io.UnsupportedEncodingException;
17 import java.net.URLEncoder; 17 import java.net.URLEncoder;
  18 +import java.util.ArrayList;
18 import java.util.HashMap; 19 import java.util.HashMap;
  20 +import java.util.List;
19 import java.util.Map; 21 import java.util.Map;
20 import java.util.concurrent.ConcurrentHashMap; 22 import java.util.concurrent.ConcurrentHashMap;
21 23
@@ -43,7 +45,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { @@ -43,7 +45,7 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
43 private static final int CONTENT_SUB_LENGTH = 250; 45 private static final int CONTENT_SUB_LENGTH = 250;
44 46
45 47
46 - public static final String DEFAULT_SENT_LOCK="sent_lock"; 48 + public static final String DEFAULT_SENT_LOCK = "sent_lock";
47 49
48 private Map<String, Long> msgSentLogMap = new HashMap<>(); 50 private Map<String, Long> msgSentLogMap = new HashMap<>();
49 51
@@ -179,8 +181,9 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { @@ -179,8 +181,9 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
179 @Scheduled(fixedRate = 5 * 60 * 1000) 181 @Scheduled(fixedRate = 5 * 60 * 1000)
180 public void clearMsgSentLog() { 182 public void clearMsgSentLog() {
181 183
182 - synchronized (DEFAULT_SENT_LOCK)  
183 - { 184 + synchronized (DEFAULT_SENT_LOCK) {
  185 + List<String> clearKeyList = new ArrayList<>();
  186 +
184 for (Map.Entry<String, Long> entry : msgSentLogMap.entrySet()) { 187 for (Map.Entry<String, Long> entry : msgSentLogMap.entrySet()) {
185 188
186 String sentKey = entry.getKey(); 189 String sentKey = entry.getKey();
@@ -191,8 +194,13 @@ public class AlarmMsgServiceImpl implements AlarmMsgService { @@ -191,8 +194,13 @@ public class AlarmMsgServiceImpl implements AlarmMsgService {
191 194
192 if (5 * 60 * 1000 <= (sentAgainTime - sentTime)) { 195 if (5 * 60 * 1000 <= (sentAgainTime - sentTime)) {
193 196
194 - msgSentLogMap.remove(sentKey); 197 + clearKeyList.add(sentKey);
  198 + }
195 } 199 }
  200 +
  201 + for (String clearKey : clearKeyList) {
  202 +
  203 + msgSentLogMap.remove(clearKey);
196 } 204 }
197 } 205 }
198 } 206 }