[concurrency-interest] Locking on local variables

Sleiman Jneidi jneidi.sleiman at gmail.com
Fri Jan 15 10:21:47 EST 2016

Hi everyone,

>From what I know, locking on local variables is useless, Brian Goetz in his
book gave the following as an example of a bad lock

 synchronized(new Object()){

So I assume, the code above is equivalent to the following

  Object o = new Object();


However looking at ConcurrentHashMap#computeIfAbsent I see the following

Node<K,V> r = new ReservationNode<K,V>();
    synchronized (r) {

Just curious, why is that?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20160115/f9f1c165/attachment.html>

More information about the Concurrency-interest mailing list