|
|
Re: Why iterator() method is required to explicitly synchronize.
|
Posted: Jun 15, 2005 8:00 AM
|
|
> Why iterator() method is required to explicitly > synchronize for a collection returned by calling > Collections.synchronizedCollection(Collection c).Why this > method is not implemented same way as others like > add(),remove() etc.
Unlike add or remove operations called on collection, iterator doesnt modifies its state.
So, in scenarios wherein multiple clients to collection, wants to just iterate over collection to find out the contents, synchronizing the access may be just an overhead.
While add , remove requires to be synchronized so that state is not inconsistent.
While if user wants to modify the state of the collection, and wants to maintain the consistency it needs to properly take care of state update.
|
|