Reputation: 193
If I have a class which has a Map
named myMap
and a getter :
public Map getMap() {
synchronized(myMap) {
return myMap;
}
}
Is getMap().put(Something)
will be synchronized too ?
Upvotes: 1
Views: 42
Reputation: 106470
No. The only thing here that is synchronized is the calling of the method to get the instance of that map. Operations on that map are not synchronized (if they aren't backed by a synchronized implementation of a map).
Upvotes: 5