aspose file tools
The moose likes Threads and Synchronization and the fly likes Concurrent Modification Exception?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Concurrent Modification Exception??" Watch "Concurrent Modification Exception??" New topic
Author

Concurrent Modification Exception??

Matthew Ballard
Greenhorn

Joined: Apr 26, 2005
Posts: 4
i am aware what the deal is with threads/CME but why is this code throwing an exception:




the method successors, takes the current state and adds all possible moves (making the move and saving the state) to an ArrayList and returns an Iterator. the line thats showing up as the trouble maker is the assignemnt, Node successor = (Node) it.next();.
i'm sure i've used this sort of thing in a while loop before and not had these issues.

any help is highely valued,
thanks - matt...
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16811
    
  19

In a nutshell, the CME is thrown when you try to modify the container, while still iterating through the same container. (You can delete the current item through, requested through the iterator) There might be something within the loop that is calling something that is changing the same container that you are trying to iterate through.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Concurrent Modification Exception??
 
Similar Threads
DOM Document creation with name spaces
How to save linkedlist to file using object serialization