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
0
votes
3 answers

Concurrent Modification Exception with Objects

I am having trouble with a Concurrent modification exception. I have changed my code to use iterators however I am still getting these issues when I remove an object. My error occurs on the line theEnemy = (Enemy) EnemyItr.next(); I'm not sure how…
Nick Haughton
  • 99
  • 1
  • 11
0
votes
2 answers

Java concurrency with arraylists (How to handle this?)

It is true that you get a ConcurrentModificationException error when you try and modify an arraylist when iterating through it, yes? But how does the error still persist if you first remove the element you want to modify, iterate through the list,…
reZach
  • 8,945
  • 12
  • 51
  • 97
0
votes
1 answer

Concurrent Modification Exception in Hashmap while using the same Hashmap in two threads

I am developing a multi-player snake game played over the network. It is running fine however it occasionally throws java.util.ConcurrentModification Exception. This is thrown in the main class of my game in the paintComponent() method. Code at…
Sohaib
  • 4,556
  • 8
  • 40
  • 68
0
votes
4 answers

ConcurrentModificationException Woes

I have a method test(), in which I am trying to compare two LinkedHashMaps against each other and modify the contents of one of the maps by removing the key/value pair if it is found in both LHM's. I keep getting a ConcurrentModificationException…
ResourceReaper
  • 555
  • 2
  • 10
  • 27
0
votes
3 answers

Java: concurrent modification exception

I am getting an error in the for(Entry...) loop where after calling dfs(), it will say concurrentmodificationexception. I don't know why it is happening even though visitedOrder is not related with the foreach loop. How can this be fixed? public…
user1375155
  • 49
  • 2
  • 7
0
votes
3 answers

How would I add points to a Google map view while still allowing the user to interact with the map?

I have a thread that receives map points which are sent from a server, and these points are added to the MapView. This works fine but if I interact with the MapView (eg. zoom in, pan, etc) I get a ConcurrentModificationException, so how can I allow…
0
votes
1 answer

Rectangle2D#getCenterY causes unrelated iterator to throw CME

I'm currently working on a game that is multi-threaded, there is one thread running the updates for the game and one thread repainting the panel that the game is being played on. After editing some code that was responsible for an enemy firing…
Neil Locketz
  • 4,228
  • 1
  • 23
  • 34
0
votes
2 answers

Android Concurrent Modification Error MapOverlays

In my app i have a MapView with custom MapOverlays. I've override the onDraw method so i will be able to cluster overlay items which are on the same position - and it work great. I'm now trying to add a large bunch of markers and i get a Concurrent…
Asaf Nevo
  • 11,338
  • 23
  • 79
  • 154
0
votes
2 answers

Concurrent Modification Exception with ArrayList

I have a problem with ConcurrentModificationException. I have an ArrayList of Complex class that I defined. I added two Complexes, and try to do a for each loop but I get the ConcurrentModificationException. However, when I remove that line, I get…
0
votes
3 answers

Getting Concurrent Modifiraction Exception. Where is the prob.lem? (code)

Im writing a simple game in Java. Here is main code: public class MainPanel extends JPanel { private Player player = new Player(100, 100, 3, 3); private Point2D targetPoint = new Point2D.Float(130, 350); //Pos on begin private…
Michał Tabor
  • 2,441
  • 5
  • 23
  • 30
0
votes
2 answers

ConcurrencyException

private static HashMap sFileInfoObjectList = new CacheLinkedHashMap(); public static synchronized FileInfo getFileInfoForProvider(...) { FileInfo foundFileInfo = null; (...) foundFileInfo =…
0
votes
3 answers

Error : java.util.ConcurrentModificationException

i have a grid from where users select the row , when a row is clicked then its id is sending to my action class AddBookToSession.java and after wards it is returning a list into my jsp page invoice.jsp I am getting error…
Dan
  • 2,086
  • 11
  • 71
  • 137
0
votes
2 answers

ConcurrentModificationExecption

I have a normal Database call that gathers information from my database. i use these informations to create my objects (CallQueue) these objects are then added to a list and the list is then returned. Suddenly i discovered that my originally code…
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
0
votes
1 answer

Make changes to domain object while in use

We have a set of domain objects that can be edited through in one window and used at the same time in other window. To ensure that the objects are in a valid state at all times and that changes are not visible to the outside world until they are…
larsmoa
  • 12,604
  • 8
  • 62
  • 85
0
votes
1 answer

ConcurrentModificationException when adding entries to ArrayList

I am trying to add some MapOverlays to my MapView and I get the following Error: java.util.ConcurrentModificationException at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569) at…
user754730
  • 1,341
  • 5
  • 31
  • 62