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:26:15 UTC
[GitHub] [dubbo] looly opened a new issue, #11986: ConcurrentHashMapUtils无法解决jdk8的循环bug
looly opened a new issue, #11986:
URL: https://github.com/apache/dubbo/issues/11986
### Environment
* Dubbo version: 3.2, 3.3
* Operating System version: Windows11
* Java version: jdk8
### Steps to reproduce this issue
[ConcurrentHashMapUtils](https://github.com/apache/dubbo/blob/3.2/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConcurrentHashMapUtils.java)
中提供的`computeIfAbsent`方法没有解决jdk8的循环问题,复现代码如下:
```java
final ConcurrentHashMap<String,Integer> map=new ConcurrentHashMap<>();
// // map.computeIfAbsent("AaAa", key->map.computeIfAbsent("BBBB",key2->42));
ConcurrentHashMapUtils.computeIfAbsent(map, "AaAa", key->map.computeIfAbsent("BBBB",key2->42));
```
[Hutool](https://github.com/dromara/hutool) 中的解决方案是:
```java
V value = map.get(key);
if (null == value) {
map.putIfAbsent(key, mappingFunction.apply(key));
value = map.get(key);
}
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.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
[GitHub] [dubbo] AlbumenJ commented on issue #11986: ConcurrentHashMapUtils无法解决jdk8的循环bug
Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ commented on issue #11986:
URL: https://github.com/apache/dubbo/issues/11986#issuecomment-1493319808
死锁这个问题可以提个 PR 改下
--
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
[GitHub] [dubbo] looly commented on issue #11986: ConcurrentHashMapUtils无法解决jdk8的循环bug
Posted by "looly (via GitHub)" <gi...@apache.org>.
looly commented on issue #11986:
URL: https://github.com/apache/dubbo/issues/11986#issuecomment-1493330046
PR see: https://github.com/apache/dubbo/issues/11986
--
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
[GitHub] [dubbo] looly commented on issue #11986: ConcurrentHashMapUtils无法解决jdk8的循环bug
Posted by "looly (via GitHub)" <gi...@apache.org>.
looly commented on issue #11986:
URL: https://github.com/apache/dubbo/issues/11986#issuecomment-1493320931
看到原来的issue和PR:
https://github.com/apache/dubbo/pull/11326
https://github.com/apache/dubbo/issues/11294
这个PR是为了解决 https://bugs.openjdk.org/browse/JDK-8161372 这个问题,但这本质上是个死锁问题。
@AlbumenJ 没有提PR就是因为两个解决方案我都不能保证逻辑是正确的,需要review验证,这也是困扰我的地方。
稍后提个PR。
--
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
[GitHub] [dubbo] AlbumenJ closed issue #11986: ConcurrentHashMapUtils无法解决jdk8的循环bug
Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ closed issue #11986: ConcurrentHashMapUtils无法解决jdk8的循环bug
URL: https://github.com/apache/dubbo/issues/11986
--
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
[GitHub] [dubbo] looly commented on issue #11986: ConcurrentHashMapUtils无法解决jdk8的循环bug
Posted by "looly (via GitHub)" <gi...@apache.org>.
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
[GitHub] [dubbo] AlbumenJ commented on issue #11986: ConcurrentHashMapUtils无法解决jdk8的循环bug
Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ commented on issue #11986:
URL: https://github.com/apache/dubbo/issues/11986#issuecomment-1493319213
ConcurrentHashMapUtils 这个主要是解决性能的问题
--
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