Erreur lors de la compilation java.util.ConcurrentModificationException

thasseda Messages postés 4 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 11 mars 2010 - 11 mars 2010 à 15:03
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 - 11 mars 2010 à 15:20
lors de la compilation de mon programme j'ai ce genre de bug


java.util.ConcurrentModificationException

at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
at java.util.HashMap$KeyIterator.next(HashMap.java:828)

1 réponse

cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
11 mars 2010 à 15:20
Salut,

C'est expliqué dans la javadoc :

Note that this implementation is not synchronized. If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections.synchronizedMap method. This is best done at creation time, to prevent accidental unsynchronized access to the map:

Map m = Collections.synchronizedMap(new HashMap(...));


Donc à chaque fois que tu modifie la structure de ton HashMap, c'est à toi de le synchroniser afin d'éviter un accès concurrentiel.
______________________________________

AVANT de poster votre message, veuillez lire, comprendre, et appliquer notre réglement
0
Rejoignez-nous