이 코드는 doSomething()에서 목록이 수정되면 동시 수정 예외를 발생시킵니다. 일부 동기화 된 블록에 코드를 포함시켜 피할 수 있습니까?Iterator 동시 수정 예외
List l = Collections.synchronizedList(new ArrayList());
// normal iteration -- can throw ConcurrentModificationException
// may require external synchronization
for (Iterator i=list.iterator(); i.hasNext();) {
doSomething(i.next());
}
는 "이 예외는 항상 객체가 동시에 * 다른 * 스레드에 의해 수정 된 것으로 표시하지 않습니다." 그럼 그건 아니오가 될거야. –
이 예외가 Throw 될 수있는 경우. –
doSomething()이 동일하거나 다른 스레드에서 'list'를 수정하는 경우. ConcurrentModificationException은 스레딩과 관련이 없습니다. – Robin