Below code occur java.util.ConcurrentModificationException, because java code try to change arraylist for iterating.
// copy is arraylist.
for (MBeanConnection notiConnection : copy) {
MetaConnectionData data = notiConnection.getMetaConnectionData();
int index = Collections.binarySearch(newConnList, data, notiComparator);
if (index >= 0) {
notiConnection.remove(index);
removedIndexList.add(index);
newConnList.remove(data);
}
}
So, java code have to change not to modify for iterating, or you have to clone the collections to avoid modification using clone() method.
List
for (MBeanConnection notiConnection : copy) {
MetaConnectionData data = notiConnection.getMetaConnectionData();
int index = Collections.binarySearch(newConnList, data, notiComparator);
if (index >= 0) {
notiConnection.remove(index);
removedIndexList.add(index);
newConnList.remove(data);
}
}
// To avoid ConncurrentModification Error
for (Integer i : removedIndexList) {
copy.remove(i.intValue());
}
No comments:
Post a Comment