[concurrency-interest] backport: ConcurrentModificationException with take() and contains()?

Holger Hoffstätte holger at wizards.de
Wed Apr 2 09:32:56 EDT 2008

serwei wrote:
> is it a confirmed scenario where a ConcurrentModificationException
> will happen when a DelayQueue.contains() is running and a
> DelayQueue.take() happens then?

That seems wrong. Which version of the backport are you using? Looks like 
an older version. I ask because..

> So I have to manually synchronized (something) for the two?
> Thanks!
> PS: stack below
> java.util.ConcurrentModificationException
>         at edu.emory.mathcs.backport.java.util.PriorityQueue$Itr.checkForComodification(PriorityQueue.java(Inlined
> Compiled Code))
>         at edu.emory.mathcs.backport.java.util.PriorityQueue$Itr.next(PriorityQueue.java(Compiled
> Code))
>         at edu.emory.mathcs.backport.java.util.concurrent.DelayQueue$Itr.next(DelayQueue.java(Compiled
> Code))
>         at java.util.AbstractCollection.contains(AbstractCollection.java(Compiled
> Code))

..looking at this stack trace it seems that the DelayQueue Iterator 
directly accesses the internal PriorityQueue without locking, however that 
is not what's happening in JDK6 or the latest backport (3.1), where the 
inherited contains() iterates over an unshared array snapshot.

Ah yes - this is the old (exception-throwing aka non-concurrent) behaviour 
in JDK5 as implemented by backport 2.x. So the easiest way to fix your 
problem is simply using the latest backport lib. That's a good idea anyway. :)


More information about the Concurrency-interest mailing list