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

Concurrent Modification Exception within a swingworker

I created a program to read a serial port, plot the data, and show the value. I am using a SwingWorker to collect, check, and plot the values while allowing the user to stop the data collection within the GUI. I believe I am receiving the…
user2755399
  • 139
  • 2
  • 4
  • 13
0
votes
2 answers

Iterator removal/edit is safe, however I also need to edit all following Iterations

I have read a little about ConcurrentModificationException in stackflow and my actual update appears not to be the issue, it could be a problem in my design or I need a technique I haven't learnt yet. Example Situation: My iterator is running along…
0
votes
1 answer

Move only file contents and not any file handler/pointer

I am working on analyzing data of a log file on frequent intervals and process accordingly. The log file which is the input, is an infinitely growing file. A long running process writes to it and it belongs to the root user. I have all the file…
thiruvenkadam
  • 4,170
  • 4
  • 27
  • 26
0
votes
2 answers

ConcurrentModificationException in removing element in ArrayList [Using iterator.remove()]

i know that we shouldn't modify the ArrayList during iteration. But i'm using Iterator to iterate over list and iterator.remove() to remove the element but still results in ConcurrentModification Exception. My program is not multithreaded. I've many…
Dineshkumar
  • 4,165
  • 5
  • 29
  • 43
0
votes
1 answer

ConcurrentModificationException in HashSet

I have my code as below and I'm getting ConcurrentModificationException, particularly in the line for (String file : files) I don't change anything for the "file" when doing iteration, so why the exception will be caused and how should I avoid it?…
Green Ho
  • 881
  • 3
  • 14
  • 27
0
votes
3 answers

A ConcurrentModificationException thrown without a modification

I have the following Java Code: HashMap overflow = new HashMap(); HashMap new_lessons = this.lessons; HashMap lessons = this.lessons; for (Integer lesson : lessons.keySet()) { …
criztovyl
  • 761
  • 5
  • 21
0
votes
1 answer

ConcurrentModificationException in AsyncTask

I have a problem with that exception inside onPostExecute() method during loop. Previously I used foreach loop, but I read that I should use ListIterator. Hopelessly it didn't fixed it. Fragment of critical code: public void search(final String…
0
votes
2 answers

java generics runtime error.java.util.ConcurrentModificationException

I have the following example java generics code which I modified as per suggestion of people on StackOverflow.Now the compilation is going through. import java.util.*; public class GenericBox { private List tList; private…
liv2hak
  • 14,472
  • 53
  • 157
  • 270
0
votes
0 answers

Shiro Eh Cache ConcurrenctModificationException

I recently added Shiro with EH Cache to my webapp and since then I am seeing a few ConcurrentModificationException: [shiro-active%0053ession%0043ache.data] ERROR net.sf.ehcache.store.disk.DiskStorageFactory - Disk Write of…
0
votes
1 answer

Universal Image Loader: I get ConcurrentModificationException when trying to remove image from cache

I need to arbitrarily replace a cached image by requesting it again from server. I'm currently using removeFromCache as follows: public void loadImage(String url, ImageView view, boolean updateCache){ if(updateCache){ …
0
votes
1 answer

ConcurrentModificationException when invoking putAll

I have difficulties in understanding the following error. Suppose you have a class A in which I implement the following method: Map get_friends(double user){ Map friends =…
user764186
  • 951
  • 2
  • 9
  • 12
0
votes
2 answers

ConcurrentModificationException in Playframework

I am getting an ConcurrentmodificationException while iterating over an object that is stored in the Cache. The Controllercode looks like this: .... SomeObj o = (SomeObj)Cache.get("obj"); for(listObj lo : o.getGetListObjects()){ …
Martin Golpashin
  • 1,032
  • 9
  • 28
0
votes
2 answers

Concurrently modifying/removing entry from HashMap without iterator

Some background to the problem: I have a class which is responsible for informing various clients about changes in service. So it the class has several HashMaps of listeners and calls their methods by iterating those HashMaps when needed (it also…
Maybe Julius
  • 1,203
  • 2
  • 13
  • 16
0
votes
1 answer

Java sibling removal throws ConcurrentModificationException

I'm having the following issue: Given: public class A{ Collection elements = new ArrayList(); } public class B{ Collection linkedElements = new ArrayList(); } All the elements of linkedElements belongs to elements too. I want…
0
votes
2 answers

Concurrent Modification Exception Cause by Painting?

I have been having a lot of trouble with the Concurrent Modification Exception error. With the help of the community I managed to fix my last error, however I think this error is more puzzling. I am now getting a concurrent modification error while…
Nick Haughton
  • 99
  • 1
  • 11