ConcurrentHashMap Put()操作示例代码

非常简练:   

1 private static void put(MetricKey key, float value) {
2         MetricValue current;
3         do {
4             current = map.get(key);
5         } while (current == null ? map.putIfAbsent(key, new MetricValue(value)) != null
6                 : !map.replace(key, current, new MetricValue(current, value)));
7 }

 

posted @ 2016-11-18 19:37  ck_2016  Views(185)  Comments(0)    收藏  举报