Multithreaded modified ArrayList, how do you know who modified it?

public void method(){
    ...
    for(Object obj: finalObjects){
        ....
        doSth(obj);
        ....
    }
}

when I was traversing ArrayList in the main thread, java.util.ConcurrentModificationException

occurred.

has checked doSth and did not modify the global variable finalObjects , so I suspect that some asynchronous method modified this variable during my traversal. Because the system is so large, it is impossible to directly find out where it has been modified. Is there any way to get it at run time, where the async is, or which thread modifies finalObjects to cause the exception?

ask the bosses, thank you!


to solve this problem, LZ can delve into the cause of ConcurrentModificationException : the enhanced for loop of
java uses the hasNext and next of the iterator iterator by default to traverse the elements. In this way, it is not difficult to understand the cause of the problem.
you execute the remove or add method elsewhere. This method only modifies the modCount value, not the expectedModCount content, so the check throws an exception

when the iterator calls next .
  

Thank you very much for your answers. Just solve the problem, such as @ kevinz, and it will be fine.
but my goal is to track which thread modified this variable during the execution of this piece of code. But it seems very difficult. I don't have a clue.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c2b439-3279e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c2b439-3279e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?