I'm having this issue and not really sure what to do. There is this HashMap contianing about 3000 to 120000 elements. Each element is mapped to an object which is never null and contains mostly longs, shorts, and ints inside. I will have one thread updating those objects continuesly and there will be dozens others reading values from those objects. So, the question is, should I synchronize the updated of the values or not?
There is a guarantee that only one thread will update one object, but many will read it or update many different objects.
If you do not sync the objects while updating them, then the readers may get broken state of the object.Fro example, if you expect to update 3 ints in the object, the updates will be atimuic, but you dont know when and at what order they will be written back to the main memory. So, the reader may see 2 updated values and 1 old.