aspose file tools
The moose likes Java in General and the fly likes An Iterator throws a ConcurrentModificationException Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "An Iterator throws a ConcurrentModificationException" Watch "An Iterator throws a ConcurrentModificationException" New topic
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
    
  11

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: An Iterator throws a ConcurrentModificationException
 
Similar Threads
About Iterator
Another Doubt in K&b exam
ConcurrentModificationException and for loops
Multiple thread accessing List (ArrayList, Vector)
RelationShip Between Iterator And Vector...