Pages

Wednesday, May 18, 2011

Example of ConcurrentModificationException


private static void refineMap(BayesianResult bayes, HashMap terms) {
for (Map.Entry entry : terms.entrySet()) {
String word = entry.getKey();
Token t = entry.getValue();
if ((t.getClean_count()+t.getSens_count()) < 10) {
terms.remove(word);
continue;
}
}
}

Here I am modifying the HashMap ( terms.remove(word) ) while iteration is already being done on it. This throws an exception Exception in thread "main" java.util.ConcurrentModificationException


No comments:

Post a Comment