The following code, I am confused about what would happen when 2 threads compete the lock for map.get(k). When thread A wins, it makes map.get(k) null and the second thread would get a synchronized(null)? Or would it be both threads see it as synchronized(v) even though the first thread changes it to null but during which thread B still sees it as v?
synchronized(map.get(k)) {
map.get(k).notify();
map.remove(k);
}
The question is a similar to another question, except lock object is value of a map.
UPDATE: compared the discussion in this post and that in the above link, is it true that
synchronized(v) {
v.notify();
v = null;
}
would cause the 2nd thread synchronized(null). But for the synchronized(map.get(k)), the 2nd thread would have synchronized(v)???
UPDATE: To answer @Holger's question, the main difference between this post and the other one is:
final V v = new V();
synchonized(map.get(k)) {
map.get(k).notify();
map.remove(k);
}