[jdom-interest] ADDING A CHILD....
laurent.bihanic at atosorigin.com
Thu Dec 12 07:15:35 PST 2002
From the JavaDoc of java.util.ConcurrentModificationException:
"[...] 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. Iterators that do this are known as fail-fast iterators, as they
fail quickly and cleanly, rather that risking arbitrary, non-deterministic
behavior at an undetermined time in the future."
JDOM's ContentList Iterator is fail-fast too. To fix the problem, you should
allocate the Iterator after having modified the list content.
Antonello Dell'Armi wrote:
> i have the element instance that have inside the elements watcher.I would like to add a new element watcher with text watcherID.
> But the following snipped of code doesn't work correctly.
> List watchers = instance.getChildren("watcher");
> Iterator iter = watchers.iterator();
> Element newatcher = new Element("watcher");
> Element watcher = (Element) iter.next();
> String w = watcher.getText();
> System.out.println("watcher= " + w);
> I get the error below. Any help? BRGS antonello
> Exception in thread "main" java.util.ConcurrentModificationException
> at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java
> at java.util.LinkedList$ListItr.next(LinkedList.java:484)
> at UPMDataManagerImpl.addWatcher(UPMDataManagerImpl.java:475)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImp
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcc
> at java.lang.reflect.Method.invoke(Method.java:324)
> at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
More information about the jdom-interest