Originally posted by Amit A. Patil:
How does it matter? If you have multiple threads modifying a Collection you will always have to synchronize it.?(Multiple writers)
Cant think of any operation that can be unsynchronized...or am i wrong?
hmmm...One Writer ...multiple Reader..still have to synchronize right?
Amit,
Peter is not saying that certain operations don't have to be synchronized -- I believe he is pointing out that just synchronization at the collection level is not enough.
For example, I have to iterate through the collection, in a
thread safe manner. In this case, only getting the iterator is synchronized, which is not good enough. I have to synchronize at a higher scope -- getting the iterator, iterating through the values to calculate a result, and possibly placing the result back.
You have to look at what you are doing and synchronize accordingly -- not just synchronize a collection because it is used by many threads.
Henry