key, V value) {}final V putVal(K key, V value, boolean onlyIfAbsentputVal(hash(key), key, value, false, true);...
final V putVal(int hash, K key, V value, boolean onlyIfAbsent
我有一张地图现在我想用原子的方式将新的对象插入到地图中,这样我就可以做如下的事情 return map.putIfAbsent(key, new V(val));但是它不是原子的,因为首先会产生新的V,然后插入到地图中。在不使用同步(或者使用同步是这里最快的方法)的情况下,有什么方法可以做到这一点吗?
of scanAndLockForPut in ConcurrentHashMap in JDK7说: HashEntry<K,V> first = entryForHash(this, hash); HashEntry<K,V> node = null;
int retries = -1; // negative while