Updating the Map objects in java -
trying use map variable key id , value custom object in java based system.
map<long, custombean> custombeanmap = new concurrenthashmap<>();
couple of questions:
during update of object in cache, best practice:
- get value based on key
- update local value
- update value in map cache // instruction needed??
since system highly concurrent , deployed in multiple cores , multiple concurrent threads active, should modifier custombeanmap must have volatile modifier?
your question ill written i'll try answer still.
- updating value specific key should done using put (map.put(, ). more important in highly concurrent environment reading value updating can lead unexpected results.
- if must read previous value in order determine next value, suggest using lock mechanism ensure actions on map done separately (unless have verified not necessary application)
- i less experienced use of volatile can't there
- your value object (the actual object in map) updating update map, naturally.
good luck, roy.
Comments
Post a Comment