For Programmers: Free Programming Magazines  


Home > Archive > Java Help > October 2004 > why java.util.ConcurrentModificationException in synchronized methods









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com