square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

Home Page:https://square.github.io/okhttp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Investigate Lock vs Synchronized performance

yschimke opened this issue · comments

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.