Object behavior
Ralph Hartley
hartley@AIC.NRL.Navy.Mil
Fri, 28 Jul 2000 08:29:09 -0400
>> for (Enumeration e = v.elements() ;e.hasMoreElements() ;) {
>> System.out.println(e.nextElement());
> Well, it is clear that the multithreaded program is broken. As far as I
> can see, there are two choices as to why: (1) the Vector documentation is
> broken, or (2) the Vector specification is broken.
Or (3) whoever included the example code in a multithread program has
not read the Vector documentation.
>From
http://www.javasoft.com/products/jdk/1.2/docs/api/java/util/Vector.html
The Iterators returned by Vector's iterator and listIterator methods
are fail-fast: if the Vector is structurally modified at any time
after the Iterator is created, in any way except through the
Iterator's own remove or add methods, the Iterator will throw a
ConcurrentModificationException. Thus, in the face of concurrent
modification, the Iterator fails quickly and cleanly, rather than
risking arbitrary, non-deterministic behavior at an undetermined time
in the future. The Enumerations returned by Vector's elements method
are not fail-fast.
Older versions of the documentation may have been broken.
Ralph Hartley