is that thread safe to update entry.value.field directly in ConcurrentHashMap? -
sometimes, need update 1 field
of entry.value
. thread safe way construct new entry.value
, use put
method update. said, need make deep copy of original value though little modification.
can update like
map[key].field = fieldvalue;
hash map returns entry safely, assignment of field out of scope of map. so, should here thread safety. code equivalent to:
entry entry = map[key]; entry.field = fieldvalue;
obviously field assignment operator doesn't know map.
Comments
Post a Comment