| Author |
why java.util.ConcurrentModificationException in synchronized methods
|
|
| RightWay 2004-10-12, 3:59 pm |
| Hi,
how is possible that a function inside a synchronized method throws a
java.util.ConcurrentModificationException??
The function inside the synchronized method is next() of an Iterator.
tnx
| |
| Matt Humphrey 2004-10-12, 8:57 pm |
|
"RightWay" <innuendong@fastwebnet.it> wrote in message
news:416c306a$1@x-privat.org...
> Hi,
> how is possible that a function inside a synchronized method throws a
> java.util.ConcurrentModificationException??
>
> The function inside the synchronized method is next() of an Iterator.
This message doesn't having anything to do with thread synchronization.
Rather, it's thrown when the collection that backs an iterator is modified
within the loop (use) of the iterator. If you need to modify the
collection while you're iterating through it, find out if your iterator will
handle that or what alternatives there are.
Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
| |
| Paul Lutus 2004-10-12, 8:57 pm |
| RightWay wrote:
> how is possible that a function inside a synchronized method throws a
> java.util.ConcurrentModificationException??
How indeed. Want us to tell you? Post your code.
> The function inside the synchronized method is next() of an Iterator.
Submit the above sentence to your Java compiler. Did it compile without
errors? Same here.
--
Paul Lutus
http://www.arachnoid.com
| |
| Bob Lied 2004-10-13, 4:00 pm |
| In article <416c306a$1@x-privat.org>,
RightWay <innuendong@fastwebnet.it> wrote:
>Hi,
>how is possible that a function inside a synchronized method throws a
>java.util.ConcurrentModificationException??
Something inside the loop is changing the collection. I've had this
problem in loops that are trying to remove from a collection, but
mistakenly write "collection.remove(entry)" instead of "iter.remove()"
--
Bob Lied
--
--
Bob Lied
|
|
|
|