classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [patch] Re: HashMap putAll/putAllInternal bug


From: David Holmes
Subject: RE: [patch] Re: HashMap putAll/putAllInternal bug
Date: Fri, 26 Sep 2003 09:10:09 +1000

Brian Jones wrote:
> Wondering how Sun's
> impl makes a copy of the given Collection while avoiding copying an
> object being modified in another thread.  Anyone know?  I think the
> Iterators are supposed to throw exceptions when this occurs too.

Most collections are not defined as being thread-safe. Even the
synchronized collections require that the user lock the collection
before iterating through it. Bottom line: It is up to the user to
ensure that a collection that is used with addAll etc is not being
modified whilst it is being added.

The ConcurrentModificationException thrown by Iterators is not just
for detecting concurrent modification by different threads (which they
may detect) but also for detecting modification of the collection by
the same thread that has an iterator active at the time the
modification is made. In simple terms they detect if you add while
iterating, or remove while iterating - other than via the iterators
remove() method.

David Holmes





reply via email to

[Prev in Thread] Current Thread [Next in Thread]