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
2 answers

ConcurrentModificationException Error using Iterators [.next()]

I need some help with an iterator that it seems no matter what I do it keeps giving me the error: Exception in thread "main" java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:859) at…
Ni6htH4wk
  • 13
  • 1
0
votes
2 answers

Getting java.util.ConcurrentModificationException in Iterator

I am trying to iterate custom object using iterator and adding data into that custom object but when size of object is 1 it's working but when I am adding second data it gives me an error : nested exception is…
user3145373 ツ
  • 7,858
  • 6
  • 43
  • 62
0
votes
2 answers

Does the repaint() get called automatically sometimes?

I'm making a game. Each object in the game is registered in a registry. I have an update and render method being called by a game loop. The render method calls repaint() on my JPanel and I have overridden paintComponent(Graphics g) for graphics.…
0
votes
1 answer

Is optimistic locking work by default in hibernate?

Step 1 In one thread, i fetched Employee for id 1 from DB in hibernate session and close the session Step 2 I started session 2, Upadted the employee name for id 1. Step 3 Now back in thread 1, i changed the employee name in detached instance.Then…
M Sach
  • 33,416
  • 76
  • 221
  • 314
0
votes
2 answers

JavaFX: ConcurrentModificationException while adding TreeItem objects in TreeView, in a seperate thread

I have the following code public void start(Stage primaryStage) { BorderPane border_pane = new BorderPane(); TreeView tree = addTreeView(); //TreeView on the LEFT …
Dimitris Sfounis
  • 2,400
  • 4
  • 31
  • 46
0
votes
3 answers

ConcurrentModificationException; cannot fix

I'm working on a plugin for a game server api known as Bukkit; this plugin allows players to play a minigame - a game within their game. The problem I'm facing is stopping the game. When the game stops, it loops through all players within that game…
Kondax Design
  • 175
  • 1
  • 1
  • 15
0
votes
5 answers

ConcurrentModificationException in foreach loop

In my code: Collection c = new ArrayList<>(); Iterator it = c.iterator(); c.add("Hello"); System.out.println(it.next()); Exception occures, because my collection changed after iterator created. But what about in this…
user3281108
  • 35
  • 1
  • 1
  • 4
0
votes
1 answer

ConcurrentModificationException in ArrayAdapter add method

I'm having a real troubling issue here, I'm encountering a ConcurrentModificationException in the ArrayAdapter.add(Object o) method. Actually the stacktrace points to to the list.size() method in the ArrayAdapter. But it's incredibly unusual since I…
Tim Kranen
  • 4,202
  • 4
  • 26
  • 49
0
votes
2 answers

Error in removing object from ArrayList in Java [Eclipse]

I have this method that removes a specific Object P from the ArrayList here is my code: public void removeProduct(Product p) throws StockException{ int flag=0; for(Product i:StockProducts) if(p.getCode()==i.getCode()){ …
0
votes
3 answers

Java error Concurrent modification Exception

I need help for this case below : I have 2 method : private void calculateTime(Map.Entry, List> entry, List processList) { List> processSpentTime = new ArrayList>(); …
Hien Vu
  • 45
  • 1
  • 1
  • 7
0
votes
2 answers

java.util.ConcurrentModificationException thrown

Error log: [26-12-13 3:16]: java.util.ConcurrentModificationException [26-12-13 3:16]: at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819) [26-12-13 3:16]: at java.util.ArrayList$Itr.next(ArrayList.java:791) [26-12-13…
user2997204
  • 1,344
  • 2
  • 12
  • 24
0
votes
2 answers

How do you interate over a Collection and modify its items without ConcurrentModificationException?

I need to do something like this... Collection myCollection; ///assume it is initialized and filled for(Iterator index = myCollection.iterator(); index.hasNext();) { Object item = index.next(); myCollection.remove(item); } Obviously…
ctrlShiftBryan
  • 27,092
  • 26
  • 73
  • 78
0
votes
2 answers

Write to file and avoid having it overwritten for x amount of time

I have an odd problem which I am trying to make solve now for a while. I have made a web app that gets data for a graph which is rendered using Highcharts. The script fetches data from the DB, saves it into a file and renders the graph using…
GSinghLDN
  • 161
  • 8
0
votes
2 answers

java.util.ConcurrentModificationException in ArrayList processing

java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372) at java.util.AbstractList$Itr.next(AbstractList.java:343) at…
0
votes
1 answer

Why concurrentmodificationexception when print a set with System.out.println()?

I am reading Java Concurrency in Practice, according to some java code in it, System.out.println() will led to ConcurrentModificationException. The code is below : private final Set set = new HashSet(); public synchronized void…
znlyj
  • 1,109
  • 3
  • 14
  • 34