I'm trying to fix a bug that occurs seldomly (a concurrentModificationException) while looping through a Set of generics Set (on the clean() method).
for (final K key : this.bean.keySet()) {
getProxy(key).clean();
}
All the answers I found suggest to use an iterator and then calling the method remove() on it but here I am not looping through a list where I need to remove an item.
There is maybe also the possibility to convert my Set to an array and lock it (using java.util.concurrent.Locks) / make it synchronous.
I am confused about the best approach to fix my problem, the solutions above don't really satisfy me as they make me lose all benefits of multithreading.