Synchronized and local copies of variables
问题 I'm looking at some legacy code which has the following idiom: Map<String, Boolean> myMap = someGlobalInstance.getMap(); synchronized (myMap) { item = myMap.get(myKey); } The warning I get from Intelli-J's code inspections is: Synchronization on local variable 'myMap' Is this the appropriate synchronization and why? Map<String, Boolean> myMap = someGlobalInstance.getMap(); synchronized (someGlobalInstance.getMap()) { item = myMap.get(myKey); } 回答1: The reason this is flagged as a problem is