[concurrency-interest] backport: ConcurrentModificationException with take() and contains()?
holger at wizards.de
Wed Apr 2 09:32:56 EDT 2008
> 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?
> PS: stack below
> 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
> at edu.emory.mathcs.backport.java.util.concurrent.DelayQueue$Itr.next(DelayQueue.java(Compiled
> at java.util.AbstractCollection.contains(AbstractCollection.java(Compiled
..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