Skip to content
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

[Enhancement] Use ConcurrentHashMap.computeIfAbsent() replace putIfAbsent(). #1400

Open
zhanghailang123 opened this issue Jul 26, 2023 · 4 comments · May be fixed by #1402
Open

[Enhancement] Use ConcurrentHashMap.computeIfAbsent() replace putIfAbsent(). #1400

zhanghailang123 opened this issue Jul 26, 2023 · 4 comments · May be fixed by #1402
Assignees

Comments

@zhanghailang123
Copy link

Is ConcurrentHashMap.computeIfAbsent() is better than putIfAbsent() ?

In my opinion , there are several advantages

1.if key exists,it is expensive to compute value, this is the most important thing
2. computeIfAbsent() is functional interface,user it will more flexible

if we need it , please assign it to me, i will try my best

@magestacks
Copy link
Member

Please list the application scenarios in the code.

@zhanghailang123
Copy link
Author

like this:
cn.hippo4j.springboot.starter.core.ClientWorker
image

It can be replaced with the following code
image

@magestacks
Copy link
Member

After submitting the change, please give the performance comparison before and after.

@magestacks magestacks added this to the 2.0.0 milestone Jul 27, 2023
@magestacks
Copy link
Member

@zhanghailang123 Welcome

@zhanghailang123 zhanghailang123 linked a pull request Jul 28, 2023 that will close this issue
@yanrongzhen yanrongzhen changed the title Use ConcurrentHashMap.computeIfAbsent() replace putIfAbsent() ? [Enhancement] Use ConcurrentHashMap.computeIfAbsent() replace putIfAbsent(). Aug 31, 2023
@magestacks magestacks removed this from the 2.0.0 milestone Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants