Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden. Du solltest ein Upgrade durchführen oder ein alternativer Browser verwenden.
Map m = Collections.synchronizedMap(new HashMap(...));
eine Threadsichere HashMap erstellen. Allerdings verstehe ich den Abschnitt über den Iterator nicht.
Java 1.4.2 API Doku hat gesagt.:
The iterators returned by all of this class's "collection view methods" are fail-fast: if the map 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.
Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs.
public class HashMap extends AbstractMap
implements Map, Cloneable, Serializable
Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) [...]
>>Heißt das, wenn ich auf die HashMap zugreife
>>und der andere Thread gerade darin schreibt
>>kriege ich eine Exception?
was heisst zugreifen: es steht doch alles da...
Wenn du einen Iterator für die keys oder values geholt hast und gerade beim durchiterieren bist UND gleichzeitig ein anderer Thread an der HashMap veränderungen vornimmt DANN bekommst du beim nächsten Aufruf von next() eine Exception
BTW trifft das auch Vector/Hashtable usw. -> einen Iterator bzw. eine Enumeration solltest du bei multithreaded Schreibzugriffen NICHT verwenden