Class A {
private Map<Oject,Object> map;
public void clear() {
map.clear();
}
public void work() {
synchronized (map) {
map.put(new Object, new Object();
}
}
}
If thread A is in the middle of the work()
method, does this mean thread B won't block if executing the clear()
method?
What is the difference between the code above and having this?
public void clear() {
synchronized (map) {
map.clear();
}
}