Synchronizing on local variable
问题 I noticed a weird construct in ConcurrentHashMap's compute and computeIfAbsent methods: Node<K,V> r = new ReservationNode<K,V>(); synchronized (r) { //... } What is the point of synchronizing on a local object considering that the JIT will most likely treat it as a no-op? 回答1: Right after the code has acquired the object’s monitor, the reference to the object is stored into the tab which is the globally visible array of nodes which make up the contents of the ConcurrentHashMap : Node<K,V> r =