Investigate Lock vs Synchronized performance
yschimke opened this issue · comments
Dead links
http://blogs.sun.com/dave/entry/java_util_concurrent_reentrantlock_vs
http://lycog.com/concurency/performance-reentrantlock-synchronized/
http://www.ibm.com/developerworks/java/library/j-jtp10264/
Medium article (no access)
https://medium.com/javarevisited/synchronized-vs-reentrantlock-how-to-choose-cfb5306080e7
2013 paper showing locks win for single threaded
https://fileadmin.cs.lth.se/cs/education/EDA015F/2013/Ch13-presentation.pdf
![image](https://private-user-images.githubusercontent.com/231923/322598724-999d5ad1-af65-418c-b277-e1037247694a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE1NjM2MzYsIm5iZiI6MTcyMTU2MzMzNiwicGF0aCI6Ii8yMzE5MjMvMzIyNTk4NzI0LTk5OWQ1YWQxLWFmNjUtNDE4Yy1iMjc3LWUxMDM3MjQ3Njk0YS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzIxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyMVQxMjAyMTZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yNzg3MjdlYzY2Nzk0MjdhYzMxZjJmMjUxMThhYzk4OWIxMWYxY2I1ODViOWZlMTcwYjc0MzI5MGNkNTYwYTdlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.2ET8UnJId8retyPNZn8sguIK4NhKUzQt8wugg4_hPjw)
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.
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.