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

Where does the ConcurrentModificationException occur?

I occassionally(random) get a ConcurrentModificationException in my app with the following exception message: java.util.ConcurrentModificationException at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:62) …
MeesterPatat
  • 2,671
  • 9
  • 31
  • 54
-1
votes
1 answer

Handle Simultaneous database updates in Java +hibernate

Hi i am working on a project and i have to handle a case when 2 users are on the same screen working on the same orders. If user 1 submits or updates an order first then i don't want user 2 to submit the same order, but instead give him a warning…
jimmyreddevil
  • 65
  • 2
  • 9
-1
votes
1 answer

Removing Object from ArrayList Causes ConcurrentModificationException

I have created a Song class that includes data members for a Song (Title, artist, album). I already have a .txt file that contains different songs which is stored into an array list. In my main class one of the functions is to allow the user to…
JCCS
  • 591
  • 8
  • 22
-1
votes
2 answers

Java Set gets full

I am making a particle emitter. Every "Rendered" object is stored in a HashSet, and when there's lots of particles on the screen, the console spits out concurrent modification exceptions. I usually have a short lifetime on these particles so they…
MCMastery
  • 3,099
  • 2
  • 20
  • 43
-1
votes
1 answer

java.util.ConcurrentModificationException in my code iter.remove() & iter.add()

I have this piece of code in my class and it throws the java.util.ConcurrentModificationException on the bolded lines (indicated with** **) public void solve() { **puzzleSolve(set.size(), sequence , set);** } //private helper method protected…
-1
votes
2 answers

Weird Concurrent Modification Exception

For some reason I have looked at lots of posts and still I don't know how to fix this. In the update method of my game, I have a for loop that updates all the existing GameObjects. private static void update() { for (GameObject g :…
MCMastery
  • 3,099
  • 2
  • 20
  • 43
-1
votes
2 answers

Java App throws ConcurrentModificationException

Here is my code: public class Test { public static void main(String[] args){ ArrayList list = new ArrayList(); list.add(1); list.add(2); list.add(2); list.add(2); list.add(5); int…
-1
votes
1 answer

Exception in thread "AWT-EventQueue-0" java.util

How do I fix this code? i don't know what this error means... I heard that it comes from having elements of a list removed during a for each loop, but I don't see anything tha I'm removing... public void paintComponent(Graphics g) { …
-1
votes
1 answer

Concurrent Modification Exception

I'm trying to make an applet of Asteroid objects that float across the screen. If two asteroids collide then the one with the lesser speed is supposed to break up into two smaller asteroids. Once an asteroid is size 1 it should vanish. When I try…
TemporaryFix
  • 2,008
  • 3
  • 30
  • 54
-1
votes
2 answers

Arraylist throws ConcurrentModificationException when it has a high number of values

So here is my issue, I have an ArrayList, it contains all of the entities that should be rendered to the screen. It does so like this with a foreach loop. for (Entity e : entities) { g.fillRect(x, y, w, h); } This works perfectly fine with no…
Darren
  • 1,774
  • 4
  • 21
  • 32
-1
votes
1 answer

Serious problems with Bukkit plugin [unexpected behavior]

Hello once again stackoverflow! I am having the hardest time with this plugin for some reason. Here are the issues. So it have a game class with a method tick i will post it, but it dose not seem to work right it will not send the debug message to…
Devin Wall
  • 180
  • 1
  • 16
-1
votes
3 answers

Java applet throws error in remove object from Iterator array

Welcome, i am programming a simple RPG game in java applet. It is getting more and more complicated and many errors are thrown to my face. Today i have problem with .remove(); method. Exception in thread "AWT-EventQueue-1"…
-1
votes
2 answers

How to lock an document under modifying?

As shown blow,sometime,the elements of embedded array comments will be modified,or an new comment will be inserted into comments as first element,and when these modifications happen,I want to lock something in minimal scope to avoid nasty…
Alex Luya
  • 9,412
  • 15
  • 59
  • 91
-1
votes
2 answers

ConcurrentModificationException with global variables but not local with local variables

In the following function I have declared local variables allPeopel and itr(they are overriding global variables). If I comment out the local variables (between the Astrixes below), then a ConcurrentModificationError is thrown. However, if I use…
-2
votes
1 answer

How to check for concurrent modification error while overriding Iterator for Linked List in Java?

I was trying to implement a doubly linked list in java and I am overriding the default Iterator interface , But how can I check for concurrent modification error inside my overridden Iterator? @Override public Iterator iterator(){ return…
Anish
  • 89
  • 1
  • 10