Java Concurrency Incrementing a Value
问题 I have been reading about volatile and synchronized in Java but have been scratching my head in confusion. I am hoping someone can help me clear up a problem private HashMap<String,int> map = new HashMap<String,int>(); In my thread if (map.get("value") == null) { map.put("value",0); } map.put("value",map.get("value")+1); My goal is to have all the threads share this map . If I add volatile it doesn't seem to fix the problem for me (I output and see that map is being override to each time). I