jdk1.7的HashMap有多线程死循环问题。
原因,双层Map,外层用了ConcurrentHashMap,但是里层还是HashMap,导致死循环。
老代码:
ConcurrentHashMap<String, Map<String, Integer>> cacheMap = new ConcurrentHashMap<>();
Map<String, Integer> result = new HashMap<>();
cacheMap.put("str",result);
新代码改为:
ConcurrentHashMap<String, Map<String, Integer>> cacheMap = new ConcurrentHashMap<>();
Map<String, Integer> result = new ConcurrentHashMap<>();
cacheMap.put("str",result);