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



_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to