Just a thought. You stated that the write rate is low, but for the sake of the argument let's suppose multiple concurrent writes / calls of the changeData
method. It is then possible that the thread that called the method the last, finishes first (in both approaches).
If your application logic assumes that the order of insertion will be honored it may yield wrong results. In that case, the body of the method changeData
is your critical section which per definition means that it should not be executed concurrently.
Critical section definition is highly sensitive to application domain semantics and the code structure, so I can't really tell if that method is to be considered a critical section. Guessing by the names of the variables, and supposing that your map is a user data cache from database, I'd guess that you can disregard this answer. But do carefully think of it, though :)
If all the writes go through this method, this would be a sketch of the code (you can use non thread safe map implementation then):
public void changeData(UUID oldId, Foo newInfo) {
synchronized(SomeClass.class) { // global lock
//update logic
}
}
This is just a sketch to illustrate the point of course. You can most probably use some of the Java concurrent constructs, if this is the problem.