记录一次ConcurrentHashMap
关键点
1)怎么判断是否存在 putIfAbsent
2)怎么加 数,使用 AtomicLong 完成计数
public ConcurrentHashMap<String, AtomicLong> summary = new ConcurrentHashMap<>();
@Override
public void update(Observable o, Object arg) {
if (arg instanceof InterfaceInfo) {
InterfaceInfo interfaceInfo = (InterfaceInfo) arg;
for (Map.Entry<String, Integer> entry : interfaceInfo.getSummaryMap().entrySet()) {
String mapKey = entry.getKey();
Integer mapValue = entry.getValue();
if (summary.putIfAbsent(mapKey, new AtomicLong(mapValue)) == null) {
continue;
} else {
summary.get(mapKey).addAndGet(mapValue);
}
}
}
}