From 7c849abf29dd848ee04c61f0074ae1d84705a9cf Mon Sep 17 00:00:00 2001 From: Awen <39176130+yu1183688986@users.noreply.github.com> Date: 星期五, 30 四月 2021 10:42:59 +0800 Subject: [PATCH] 修复集合遍历删除元素的java.util.ConcurrentModificationException 异常问题 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java index 129f8a3..a69cec8 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java @@ -63,15 +63,44 @@ } } - if (result) { + if (null != result && result) { event = eventMap.get(key); } } return event; } + public void removeSubscribe(HookType type, JSONObject hookResponse) { + Map<JSONObject, Event> eventMap = allSubscribes.get(type); + if (eventMap == null) { + return; + } + Iterator<Map.Entry<JSONObject, Event>> iterator = eventMap.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry<JSONObject, Event> next = iterator.next(); + JSONObject key = next.getKey(); + Boolean result = null; + for (String s : key.keySet()) { + if (result == null) { + result = key.getString(s).equals(hookResponse.getString(s)); + }else { + result = result && key.getString(s).equals(hookResponse.getString(s)); + } + + } + if (null != result && result){ + iterator.remove(); + } + } + } + + /** + * 鑾峰彇鏌愪釜绫诲瀷鐨勬墍鏈夌殑璁㈤槄 + * @param type + * @return + */ public List<ZLMHttpHookSubscribe.Event> getSubscribes(HookType type) { - ZLMHttpHookSubscribe.Event event= null; + // ZLMHttpHookSubscribe.Event event= null; Map<JSONObject, Event> eventMap = allSubscribes.get(type); if (eventMap == null) { return null; -- Gitblit v1.8.0