作者 钟来

修改清楚缓存的bug

@@ -10,6 +10,7 @@ import net.jodah.expiringmap.ExpiringMap; @@ -10,6 +10,7 @@ import net.jodah.expiringmap.ExpiringMap;
10 import org.slf4j.Logger; 10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
12 12
  13 +import java.util.Iterator;
13 import java.util.concurrent.TimeUnit; 14 import java.util.concurrent.TimeUnit;
14 15
15 /** 16 /**
@@ -61,15 +62,17 @@ public class DeviceCach { @@ -61,15 +62,17 @@ public class DeviceCach {
61 } 62 }
62 public static void cleanDeviceHost(String deviceId) 63 public static void cleanDeviceHost(String deviceId)
63 { 64 {
64 - if (parserDeviceHostDtoMap.containsKey(deviceId))  
65 - {  
66 - parserDeviceHostDtoMap.remove(deviceId);  
67 - }  
68 - for (String key :parserDeviceInfoDtoMap.keySet()) 65 + // 直接移除 host(无需先检查 containsKey)
  66 + parserDeviceHostDtoMap.remove(deviceId);
  67 +
  68 + // 使用显式迭代器并调用 iterator.remove() 避免 ConcurrentModificationException
  69 + Iterator<String> it = parserDeviceInfoDtoMap.keySet().iterator();
  70 + while (it.hasNext())
69 { 71 {
70 - if(key.startsWith(deviceId+"_")) 72 + String key = it.next();
  73 + if (key.startsWith(deviceId + "_"))
71 { 74 {
72 - parserDeviceInfoDtoMap.remove(key); 75 + it.remove();
73 } 76 }
74 } 77 }
75 } 78 }