遇到的问题
项目中用到consul作为配置中心,在修改consul配置时,会发现服务报出集合类修改异常:
java.util.ConcurrentModificationException
at java.util.ArrayList.forEach(ArrayList.java:1260)
问题分析
Java1.8
// ArrayList 部分源码
public void forEach(Consumer<? super E> action) {
Objects.requireNonNull(action);
final int expectedModCount = modCount;
@SuppressWarnings("unchecked")
final E[] elementData = (E[]) this.elementData;
final int size = this.size;
for (int i=0; modCount == expectedModCount && i <