A.DUPONCHEL
A.DUPONCHEL

Reputation: 193

Is action synchronized when the getter is too?

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

Answers (1)

Makoto
Makoto

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

Related Questions