We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
> 尝试升级到5.8.23,使用了computeIfAbsent方法应该没有重复创建问题。
我用的是jdk1.8,调用的是computeIfAbsentForJdk8,多线程情况下,因为没有加锁,map.get(key)会有多个线程返回null,mappingFunction.apply(key)还是存在多次执行的情况,所以问题仍然存在。
Originally posted by @lichriszhang in #3435 (comment)
The text was updated successfully, but these errors were encountered:
针对jdk8的处理,虽然方法名是computeIfAbsent,但内部调用还是putIfAbsent
Sorry, something went wrong.
@lichriszhang sorry,我这边测试没有切换JDK导致的。
为了解决恶心的JDK-8161372死循环问题,不得不改造这个方法。
JDK-8161372
确实改造后由于非原子可能造成对象重复创建的问题。
不过我觉得这个重复创建并不影响最终单例对象的唯一性。
可以看下MapUtil.computeIfAbsentForJdk8方法:
MapUtil.computeIfAbsentForJdk8
步骤1中创建了对象,步骤2会重复判断,判断有值后会抛弃创建的对象。
也就是说,为了解决这个bug并照顾到性能问题,退而求其次选择了这个方案。
JDK9+无此问题。
No branches or pull requests
我用的是jdk1.8,调用的是computeIfAbsentForJdk8,多线程情况下,因为没有加锁,map.get(key)会有多个线程返回null,mappingFunction.apply(key)还是存在多次执行的情况,所以问题仍然存在。
Originally posted by @lichriszhang in #3435 (comment)
The text was updated successfully, but these errors were encountered: