Following up on this question (Java thread safety - multiple atomic operations?), I don't want to add more questions to it, but now I have this doubt:
private final Map<String, Set<String>> data = Maps.newConcurrentMap();
... then in a method ...
if (data.containsKey("A")) {
data.get("A").add("B");
}
It should be something like this:
synchronized(data) {
if (data.containsKey("A")) {
data.get("A").add("B");
}
}
In order to be thread-safe. Is that correct?
So operations are atomic, but combining them would require synchronisation, is that right? At that point, would it make sense to just use a simple HashMap instead of a concurrent one, as we're manually handling sync?
Is there any method in CHM to make this work atomically?