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:

  1. during update of object in cache, best practice:

    • get value based on key
    • update local value
    • update value in map cache // instruction needed??
  2. 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.

  1. updating value specific key should done using put (map.put(, ). more important in highly concurrent environment reading value updating can lead unexpected results.
  2. 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)
  3. i less experienced use of volatile can't there
  4. your value object (the actual object in map) updating update map, naturally.

good luck, roy.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -