ConcurrentModificationException while iterating on Iterator
1 posts in topic
Flat View  Flat View

Posted By:   ajay_khatri
Posted On:   Thursday, January 15, 2004 09:32 PM

I have a HashMap object. On that object i'm getting entry set object(obj.entrySet()). Than i got an Iterator object from Set. While iterating over Iterator object i'm getting
What can be the problem?


Re: ConcurrentModificationException while iterating on Iterator

Posted By:   Anjan_Bacchu  
Posted On:   Thursday, January 15, 2004 09:49 PM


Note that this implementation is not synchronized. If multiple
* threads access this map concurrently, and at least one of the threads
* modifies the map structurally, it must be synchronized externally.
* (A structural modification is any operation that adds or deletes one or
* more mappings; merely changing the value associated with a key that an
* instance already contains is not a structural modification.) This is
* typically accomplished by synchronizing on some object that naturally
* encapsulates the map. If no such object exists, the map should be
* "wrapped" using the Collections.synchronizedMap method. This is
* best done at creation time, to prevent accidental unsynchronized access to
* the map:

 Map m = Collections.synchronizedMap(new HashMap(...));


The iterators returned by all of this class's "collection view methods"
* are fail-fast: if the map 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.

About | Sitemap | Contact