I recently looked at ConcurrentHashMap java 1.8 source code, and there whole implementation is changed from java 1.7. And specifically I am more interested in knowing why for locking purpose they are now using synchronized
instead of Reentrantlock in 1.7.
If someone could provide some pointers or point me to some articles explaining drawback in 1.7 version.
Asked
Active
Viewed 1,862 times
2

Vip
- 1,448
- 2
- 17
- 20
-
Only a guess: synchronized is more readable than ReenrantLock, at the cost of flexibility and maybe efficiency. My guess is that the added flexibility is not needed, and the efficiency on synchronized improved to the point of it being a better choice. – Yoav Gur Jun 22 '18 at 06:33
1 Answers
1
According to this answer the amount of changes that were necessary to implement the new features of Java 8 (lots of extra methods on the Map
interface) called for a rewrite.
There is also another thread with the same specific question you have about using intrinsic locks instead of Lock objects (but it went unanswered).

Thilo
- 257,207
- 101
- 511
- 656