It looks like I'm not the only one having a problem with a bug that causes the ConcurrentModificationException, but I didn't want to high-jack Tom's thread.
I'm trying to track down a ConcurrentModificationError. I've got some code that uses separate threads to iterate over a single Java Collection. The tricky part is during the iteration an object that implements the Runnable interface is created and sent to the AWT Event Dispatching Thread. Someone told me that this code can't be the source of the exception becuase the actions encapsulated by the objects implementing runnable are executed seqentially on the AWT Event Dispatching Thread. Therefore, the Java Collection couldn't be getting modified at the same time.
Here is my question. The code that actually iterates over the collection appears outside of the AWT Event Dispatching Thread. This means that the Java Collection could be interated over by 2 separate threads at the same time, although in this case we aren't "modifying" the actual objects stored in the collection, or the order of the objects in the collection.
Can the act of iteration over a collection by multiple threads cause the ConcurrentModificationException, or do the threads have to actually change something about the collection or the objects it stores?
Thanks,
Landon
P.S. - Here is the applicable section of the Javadoc for ConcurrentModificationException:
Note what the Javadoc for the ConcurrentModificationException thread states:
"it is not generally permssible for one thread to modify a Collection while another thread is iterating over it. In general, the results of the iteration are undefined under these circumstances. Some Iterator implementations (including those of all the collection implementations provided by the JRE) may choose to throw this exception if this behavior is detected."