儘管使用迭代器執行刪除操作,但我收到ConcurrentModificationException。任何想法爲什麼?ConcurrentModificationException拋出iterator.remove
for (Iterator<Thread> iter = threads.iterator(); iter.hasNext();) {
Thread hook = iter.next();
if(someCondition){
iter.remove();
}
}
我的猜測是另一個線程正在搞亂線程列表。有些線程可能會在列表中添加某些內容? – aioobe
你是不是也在同一時間修改? –