I'm getting a ConcurrentModificationException
Hello,
I'm having trouble with a ConcurrentModificationException. I've got a LinkedList with more than one ListIterator tracking it. For some reason, if I call the next() method on one, and then do the same for another, it throws a ConcurrentModificationException. I did a bit of research on this and I found that it happens when an iterator is trying to traverse the list while something else is trying to modify it. It's strange because I'm sure nothing is modifying the list, but maybe it thinks that if another iterator is trying to traverse the list that counts as a modification. But in any case, one solution I came across was to synchronize the call to next(). I tried this but I'm not having any luck. Maybe it's because I don't know how to used synchronization, but here's what I've tried:
Code:
synchronized (pointList) {
p = (Point) iterator.next();
}
I've also tried this:
Code:
synchronized (this) {
p = (Point) iterator.next();
}
Needless to say, the call to next() is not made within pointList. I'm not sure what goes into the brackets of synchronized, but I'm sure it has to be whatever needs protection from modification while the call to next() is made, so I initially tried pointList.
Anyway, it isn't working. I'm still getting the ConcurrentModificationException.
Any help would be much appreciated.