when I iterate the hashmap, I want to remove some entries according to some conditions. but it fails, becasuse hashmap is not threadsafe, it can not be accessed by mutithread at the same time. Then I wrapped hashmap to the threadsafe map, but it fails too. I dont know why ...... need some answer, thanks
HashMap hm = new HashMap();
hm.put(1, "test1");
hm.put(2, "test2");
Map m = Collections.synchronizedMap(hm);
Set keys = m.keySet();
for(Iterator it = keys.iterator(); it.hasNext(); ) {
int key = (Integer) it.next();
if(key == 1) {
m.remove(key);
}