Questions tagged [concurrentmodification]

Concurrent modification is a common problem with some thread-using applications, when not properly using locks/syncronization. It may cause errors or exceptions, such as ConcurrentModificationException in Java.

Concurrent modification is an error that may come up at random times in threaded code. For example, consider two functions, to withdraw and add from an account:

public variable dollars

add(amount):
   add amount to dollars
   sets dollars amount


withdraw(amount):
   subtract amount from dollars
   sets dollars amount

If this pseudocode example had two threads running, it would be possible to add one to the number (100 to 101 dollars), concurrently dispensing $100 to customer and setting account to 0, then set the account to 101 dollars.

Different languages handle this differently, for example Java has synchronized(object with lock), GTK has gtk_threads_enter/leave for interacting on single thread.

622 questions
-3
votes
1 answer

concurrent modification exception in for loop in java with list

class A{ private List users; public List getusers(){ users.trimToSize(); return users; } class B{ public static void main(String[] args){ for(String user:getusers()){ …
Anju Singh
  • 367
  • 1
  • 13
-3
votes
1 answer

Concurrent Modification Exception Writing to Realm in onPostExecute method - Android

I am using Realm as my Database. And while inserting/updating the data I am getting the following error FATAL EXCEPTION: main Process: uk.org.humanfocus.hfi, PID: 6430 java.util.ConcurrentModificationException at…
Salmaan
  • 3,543
  • 8
  • 33
  • 59
-3
votes
1 answer

Why is java.util.ConcurrentModificationException being raised here?

This exception rises up Exception in thread "main" java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(Unknown Source) at java.util.ArrayList$Itr.next(Unknown Source) at…
hmnhmn
  • 173
  • 2
  • 9
-4
votes
1 answer

I have code with for-loop and I always have got concurrent modification exception and i dont know how to solve it

I am programming a sorting system to school that must split some people into two cars, but I am stuck and I don't know how to continue. When I delete the second when, it was working. But I need it there so I don't know what to do. I already tried…
Stepan
  • 5
  • 3
-4
votes
2 answers

ConcurrentModificationException with for loop

I am getting a ConcurrentModificationException with my for loop and I do not know how to solve this problem. This is my code: for(Map.Entry entry:oldPresentationMap.entrySet()) { …
-6
votes
5 answers

Removing all instances of Person from a List whose name field matches a given parameter

An exercise demands that all people matching a given name parameter be removed from a List collection. The solution must use a for-each loop. The solution presented below, does not throw any compile-time errors at me, but but it fails to pass one…
user695696
  • 155
  • 3
  • 6
  • 11
-6
votes
2 answers

Concurrent Modification Error for Object ArrayList

I have searched for an answer to my problem but nothing has worked. This is my code. public ArrayList checkList() { Criteria a = this.getCriteria(); ArrayList z = this.getExercise(); for(Exercise c : z) { …
user3794468
  • 1
  • 1
  • 4
1 2 3
41
42