이 간단한 작업 스레드를 작성하여 ArrayList 반복을 통해 회문을 계산했습니다. temp_str1 = it.next(); 행을 실행할 때 오류가 발생합니다. ArrayList buffer_List는 다른 스레드에서 사용하지 않으므로 동기화 된 블록을 사용하면 도움이되지 않습니다. 이전 질문을 살펴 봤는데 도움이되지 못했습니다. 나는이 문제에 대한 해결책을 찾고 싶어한다.iterator.next()의 ConcurrentModificationException 다중 스레드
private void find_Palindromes(ArrayList<String> buffer_List){
Iterator<String> it = buffer_List.iterator();
String temp_str1, temp_str2;
while(it.hasNext()){
temp_str1 = it.next();
//System.out.println(temp_str1);
it.remove();
if(is_Palindrome(temp_str1)){
to_Shared_Queue(temp_str1);
palin_count++;
}
}
}
편집 코드 : to_Shared_Queue
private void to_Shared_Queue(String str){
synchronized(shared_queue){
Shared_queue.add(str);
}
}
[mcve]하시기 바랍니다. –
이 사람의 대답을보고, 당신을 도울 수 있습니다. 그것은 당신이 ArrayList에서 항목을 제거하는 데 사용하는 제거 메서드입니다. http://stackoverflow.com/questions/15993356/how-iterators-remove-method-actually-remove-an-object – kevto
to_Shared_Queue 메서드에서 buffer_List를 수정하려고합니다. – MGorgon