You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "looly (via GitHub)" <gi...@apache.org> on 2023/04/02 12:29:04 UTC

[GitHub] [dubbo] looly commented on issue #11986: ConcurrentHashMapUtils无法解决jdk8的循环bug

looly commented on issue #11986:
URL: https://github.com/apache/dubbo/issues/11986#issuecomment-1493319150

   但是有issue反馈说这种方式获取的value有可能为null,我不确定这种写法是否存在问题。
   
   issue中提出的替代方案是:
   
   ```java
   V value = map.get(key);
   if (null == value) {
   	value = mappingFunction.apply(key);
   	final V res = map.putIfAbsent(key, mappingFunction.apply(key));
   	if(null != res){
   		// issues#I6RVMY
   		// 如果旧值存在,说明其他线程已经赋值成功,putIfAbsent没有执行,返回旧值
   		return res;
   	}
   	// 如果旧值不存在,说明赋值成功,返回当前值
   }
   return value;
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org