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.
Help will be appreciated.
Yaroslav Chinskiy
Ranch Hand
Joined: Jan 09, 2001
Posts: 147
posted
0
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.
vinay prasad
Greenhorn
Joined: Jun 15, 2004
Posts: 8
posted
0
Hashtable implements syncronized this should not cause any problem...
Yaroslav Chinskiy
Ranch Hand
Joined: Jan 09, 2001
Posts: 147
posted
0
I think that he updates the content of the objects that r stored in the hashmap. So using Hashtable does not make any diff.