The synchronized card, as the name implies, is synchronized. Each operation on it is atomic with respect to any other operation on it.
You can think of it as if every method of your synchronized map is declared with the synchronized .
Please keep in mind that although individual operations are atomic, if you combine them, they are no longer atoms, for example:
String value = map.get("key"); map.put("key", value+"2");
not equivalent to your custom synced code:
synchronized (map) { String value = map.get("key"); map.put("key", value+"2"); }
but rather:
synchronized (map) { String value = map.get("key"); } synchronized (map) { map.put("key", value+"2"); }
source share