java.util.ConcurrentModification handling in java -
I am trying to read and write in a list in the same block as shown in the code below. DoerDao GetParentNode method will give me an integer number and I am storing it again in the same list. I know that this gives me a concurrent amendment error, but is there any way where I can lock the object, can I use the same list object to store the value and read it from the list at the same time? Or I will have to write a new method and then use it to get all the data in the list.
int moduleId = 10; & Lt; Integer & gt; GetParentNode = New Arreelist & lt; Integer & gt; (); Try {getParentNode} {getParentNode.add (moduleId); (For int node: getParentNode) {int nodeId = doerDao.getParentNode (sessionFactory, node); GetParentNode.add (nodeId); }}} Hold (exception e) {e.printStackTrace (); Logs. Terror ("Error:" + E); }
Keep in mind that concurrent modification
this In case do nothing with threads and synchronization! In your case, an iterator is used for the list after that the list was modified.
In your case, for a simple calculation - I will get rid of each loop, this iterator.
Comments
Post a Comment