I have next code in background thread
private List<IStartAction> mActions = Collections.synchronizedList(new ArrayList<IStartAction>());
protected void removeNonApplicableActions() {
Iterator<IStartAction> iterator = mActions.iterator();
while (iterator.hasNext()) {
IStartAction action = iterator.next();
if (!action.isApplicable()) {
iterator.remove();
}
}
}
When i run this in main thread got ConcurrentModificationException into iterator.next(). Why is this happening? I use thread-safe collection and remove items through iterator. Collection used in only this thread.
ConcurrentModificationExceptionisn't necessarily indicating you have multiple threads modifying your list, it's that you are concurrently iterating through your list and modifying it at the same time.isApplicable()do? Does it modifymActionsin any way?