java - which thread will get concurrentModificationException with two threads -
i have 2 thread 1 thread adding,removing in arraylist , thread iterating iterator arraylist. thread concurrentmodificationexcetion;
the thread iterator. it's iterator detects (on best effort basis) underlying collection has changed, , throws exception.
of course common situation concurrentmodificationexception
when using single thread both iterates collection , attempts modify it:
list<string> foo = ... ; for(string s : foo) { // exception thrown here after 1st iteration foo.add("let's throw exception!"); }
Comments
Post a Comment