Sometimes, we need to update one
the thread safe way to do that is construct a new
put method to update. that is said, I need to make deep copy
of original value even though I just do some little modification.
Can I do this update like
map[key].field = fieldValue;
Hash map returns an entry safely, but assignment of a field is out of scope of the map. So, you should do something here for thread safety. Your code is equivalent to:
Entry entry = map[key]; entry.field = fieldValue;
Obviously the field assignment operator doesn't know anything about the map.
Maybe a lock for the entry itself is needed. If it is just an assignment, then volatile.