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

Investigate Lock vs Synchronized performance #8366

Closed
yschimke opened this issue Apr 15, 2024 · 4 comments
Closed

Investigate Lock vs Synchronized performance #8366

yschimke opened this issue Apr 15, 2024 · 4 comments
Labels
bug Bug in existing code

Comments

@yschimke
Copy link
Collaborator

No description provided.

@yschimke yschimke added the bug Bug in existing code label Apr 15, 2024
@yschimke
Copy link
Collaborator Author

2013 paper showing locks win for single threaded

https://fileadmin.cs.lth.se/cs/education/EDA015F/2013/Ch13-presentation.pdf

image

@yschimke
Copy link
Collaborator Author

yschimke commented Apr 15, 2024

A bunch of github issues for updating projects like pgjdbc/pgjdbc#1951

With a link to 2023 article https://www.mo4tech.com/comparison-of-synchronized-and-reentrantlock-performance-in-java.html Comparison of Synchronized and ReentrantLock performance in Java

There is no doubt that synchronized performs 20-30% worse than ReentrantLock, so should lock be used everywhere in your code that synchronized is used? No, if you think about it, ReentrantLock is a better substitute for almost any scenario that uses synchronized, so why does the JDK stick with this keyword? And there is absolutely no desire to scrap it.

@yschimke
Copy link
Collaborator Author

cc @swankjesse I think the only real way is to benchmark your app, with a known workload, before and after on a specific JVM and architecture. I don't think it's a one is faster than the other deal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests

1 participant