Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Looking through collections  RSS feed

 
Tiffany Gorch
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This from the (Java 2) javadoc entry for java.util.Vector:
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.
So... if Enumerations are not "fail-fast" what are they? Fail-slow? Don't-fail? And if they don't fail, does using an Enumeration lock up (synchronize) your Vector until you are done enumerating?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enumerations do not consider the possibility of concurrent modifications, so if you do not do appropriate synchronisation and/or checks yourself, you may skip or double-up on elements, if there has been a modification since you started enumerating.
At least, that's what I conclude from the JDK source for Vector (implements the enumeration) and AbstractList (implements the iterator).
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spot on.
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!