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
2
votes
1 answer

Why do I get a ConcurrentModificationException even though I do not edit anything?

I am trying to convert some serial code into some 'nice' multithreaded code, but when I try to run it, I get a java.util.ConcurrentModificationException of the iterator from the point I get more than 200 elements in the Set I'm iterating over. I…
2
votes
0 answers

SynchronizedList gets null values while swapping

I'm trying to write a "swap-list", think double buffer but for objects instead of raw bytes. Basically I'm doing this to cut down on contention, so one task can do a lot of removals while the swapped list is added to. public class SwapList { …
Aage Torleif
  • 1,907
  • 1
  • 20
  • 37
2
votes
4 answers

Avoiding unnecessary ConcurrentModificationException on iteration

I have a large quantity of things, a thread that repeatedly iterates over them, and a separate thread that occasionally removes or adds individual things. The things are in a synchronized linked list: private List things =…
mk.
  • 11,360
  • 6
  • 40
  • 54
2
votes
0 answers

Mongoose versionKey not showing in where clause of update

I am trying to get the versionKey working in mongoose to protect against concurrent modification. I have constructed a test where I read in the account twice (account1 and account 2) modify account1 save it, modify account2 save it and expect a…
lach
  • 21
  • 3
2
votes
1 answer

JAVA java.util.ConcurrentModificationException:null Exception

I am working on my code and getting "java.util.ConcurrentModificationException". I googled it and also know that such error comes only when you try to modify on-going iterative variable, which I don't feel in my case. Below is my code. // This line…
Pratik
  • 367
  • 2
  • 4
  • 11
2
votes
1 answer

Consuming from Kafka failed Iterator is in failed state

I am getting exception while consuming the messages from kafka. org.springframework.messaging.MessagingException: Consuming from Kafka failed; nested exception is java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Iterator is…
2
votes
2 answers

Java ConcurrentModificationException when iterating ArrayList

I get ConcurrentModificationException when iterating an ArrayList and adding objects to a secondary ArrayList. I don't really know why because I'm not editing the list that I'm iterating through. This happens in two parts of my code. These are the…
user2099024
  • 1,452
  • 4
  • 16
  • 26
2
votes
1 answer

How to avoid the ConcurrentModificationException

I am trying to remove items from an array list with an iterator and I keep getting the ConcurrentModificationExceptionhere is my code: public void forward() { for (Sprite s : sprites) { s.move(); for (Iterator iter =…
cwendel
  • 67
  • 1
  • 7
2
votes
2 answers

Java: ConcurrentModificationException, 3 threads, different lists, same objects

I have the following situation: In a main function if some controller class I retrieve 10 product objects from my DB. These are hold in an ArrayList object. Afterwards I create three classes which extend Runnable and I give to each class the…
2
votes
2 answers

ConcurrentModificationException on for loop on java.util.Set

This is may be duplicate question but I am a bit confuse in ConcurrentModificationException. I gone through some other questions on stack Overflow also some articles related to How to avoid ConcurrentModificationException. I come to know that this…
Amogh
  • 4,453
  • 11
  • 45
  • 106
2
votes
5 answers

How to add values to a list while iterating it

I Have a scenario such like this List xxx = new ArrayList for(String yyy : xxx){ for(String zzz:xyxy){ if(!zzz.equals(yyy)){ xxx.add(zzz); } } } But i get java.util.ConcurrentModificationException: null exception.Can…
2
votes
2 answers

Concurrent Modification Exception in Java Set

As a part of my program I stuck to Concurrent Modification Exception. Here is the mentioned part: PriorityQueue marginalGainHeap = new PriorityQueue( 1, new Comparator() { public int…
Ali
  • 1,759
  • 2
  • 32
  • 69
2
votes
3 answers

ConcurrentModificationException is not thrown in DVM for 1 list member

The following code crashes(Concurrent modification exception) in JVM but not in DVM, i am unable to understand why its not crashing in andorid. I am using JB List list = new ArrayList(); list.add("Something");//add only 1…
Ankit Khare
  • 99
  • 2
  • 11
2
votes
1 answer

java.util.ConcurrentModificationException using an Iterator

I have looked around and cannot find anything that matches or that fixes my problem. I am trying to make a very basic server system right now that will go onto something more advanced. For some reason if more than one client tries to join it will…
2
votes
1 answer

How to correctly animate images in a data structure and not get ConcurrentModificationException

For those who hate reading long questions, take the complete code below, run it, hit SPACE a few times, and you'll get a ConcurrentModificationException. Simple question: How do you fix it? The problem is trying to remove a Fireball from the list…
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720