| Author |
An Iterator throws a ConcurrentModificationException
|
Ravi Kiran Va
Ranch Hand
Joined: Apr 18, 2009
Posts: 2234
|
|
Hi ,
An Iterator throws a ConcurrentModificationException if an Collection Object is being Modified at the time of Iteration .
Does this applicable to Objects such as a Vector , as this is an already inbuilt Synchronized ??
Please share your ideas .
|
Save India From Corruption - Anna Hazare.
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
|
|
The Vector API says :
The Iterators returned by Vector's iterator and listIterator methods are fail-fast: if the Vector is structurally modified at any time after the Iterator is created, in any way except through the Iterator's own remove or add methods, the Iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the Iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future. The Enumerations returned by Vector's elements method are not fail-fast.
And also, a ConcurrentModificationException is not limited to multi threads. As you can understand from the API excerpt above, it may also happens in a single thread. So "this is an already inbuilt Synchronized" is not relevant.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Ravi Kiran Va
Ranch Hand
Joined: Apr 18, 2009
Posts: 2234
|
|
|
Great answer .Thanks
|
 |
 |
|
|
subject: An Iterator throws a ConcurrentModificationException
|
|
|