-
Notifications
You must be signed in to change notification settings - Fork 26.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConcurrentHashMapUtils无法解决jdk8的循环bug #11986
Labels
type/bug
Bugs to being fixed
Comments
但是有issue反馈说这种方式获取的value有可能为null,我不确定这种写法是否存在问题。 issue中提出的替代方案是: 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; |
ConcurrentHashMapUtils 这个主要是解决性能的问题 |
死锁这个问题可以提个 PR 改下 |
看到原来的issue和PR: 这个PR是为了解决 https://bugs.openjdk.org/browse/JDK-8161372 这个问题,但这本质上是个死锁问题。 @AlbumenJ 没有提PR就是因为两个解决方案我都不能保证逻辑是正确的,需要review验证,这也是困扰我的地方。 稍后提个PR。 |
PR see: #11986 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Environment
Steps to reproduce this issue
ConcurrentHashMapUtils 中提供的
computeIfAbsent
方法没有解决jdk8的循环问题,复现代码如下:Hutool 中的解决方案是:
The text was updated successfully, but these errors were encountered: