Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Tags more
Archives
Today
Total
관리 메뉴

공부블로그

java.util.ConcurrentModificationException 예외 본문

IT/JAVA

java.util.ConcurrentModificationException 예외

So1_b 2022. 7. 26. 19:55

멱집합 알고리즘을 풀다가 발생한 예외

 

알게된 점 )

 

for-each문은 배열이나 Iterable인터페이스를 구현하는 객체만 대상이 될 수 있는데

그 이유는 내부에서 Iterator를 사용하는 형태로 변경되어 인식되기 때문이다.

 

ArrayList의 경우 ArrayList.Itr 내부클래스를 통해 Iterator객체가 생성됨.

ArrayList의 상위 클래스에 데이터의 변경사항을 카운트하는 modeCount전역변수가 존재하는데

Iterator객체가 생성될 때 modeCount값으로 expectedModecount변수를 초기화시킨다.

 

ArrayList$Itr.class의 일부분

그리고 next()가 호출될 때마다 modeCount변수와 expectedModecount변수를 비교하고 

다를경우 java.util.ConcurrentModificationException예외 발생

 

즉 modCount를 변경시키는 메서드를 사용후 next()를 호출하게 되면 예외가 발생된다

 

참고 사이트

https://jistol.github.io/java/2019/11/24/concurrentmodificationexception-with-ehcache/

'IT > JAVA' 카테고리의 다른 글

스레드(Thread)  (0) 2022.07.07
컴파일 세부 과정  (0) 2022.05.12
JVM 구조  (0) 2022.05.07
No consoles to display at this time 오류  (0) 2022.04.16
이클립스 exit code=-805306369  (0) 2022.03.30
Comments