FAQ Database Discussion Community


How do I fix java.util.ConcurrentModificationException?

java,concurrentmodification
The purpose of my code is to have the user enter a car name, then search through the array list and find an object that matches what the user entered. Whenever I run the code, I get the java.util.ConcurrentModificationException error. An explanation of what this error means and advice for...

Concurrent updates (x += a) to global memory in OpenCL

opencl,concurrentmodification
I'm doing the following in an OpenCL kernel (simplified example): __kernel void step(const uint count, __global int *map, __global float *sum) { const uint i = get_global_id(0); if(i < count) { sum[map[i]] += 12.34; } } Here, sum is some quantity I want to calculate (previously set to zero in...

concurrent modification on arraylist

java,for-loop,arraylist,concurrentmodification
There are a lot of concurrent mod exception questions, but I'm unable to find an answer that has helped me resolve my issue. If you find an answer that does, please supply a link instead of just down voting. So I originally got a concurrent mod error when attempting to...

Removing Object from ArrayList Causes ConcurrentModificationException

java,file-io,arraylist,concurrentmodification
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 delete a song...

Java Threads with ConcurrentModificationException

java,multithreading,exception,arraylist,concurrentmodification
I'm currently working on my first multithreaded software - a program, which calculates prime numbers... Basically I create n (number of Threads) runnables. These runnables are added to an ArrayList. They check, whether a number is a prime. If the number is a prime I add it into an...

FATAL EXCEPTION: AsyncTask caused by ConcurrentModificationException

java,android,android-asynctask,concurrentmodification
I am new to Android and developing in general so any help is appreciated. Most of the questions (and answers) about a "FATAL EXCEPTION in an AsyncTask" were NullpointerExceptions so I think I am allowed to ask. I use this Midi-driver https://github.com/kshoji/USB-MIDI-Driver to get notes from an external keyboard. I...

Avoiding Concurrent Modification

java,rendering,standards,deep-copy,concurrentmodification
Let's say I'm making a game where the screen is updates as often as possible within the frame-rate limit, but objects are only updated on a game-tick clock. How would I render complex objects without risking concurrent modification? For instance, if I needed the rendering engine to access detailed information...

Why doesn't my sample throw ConcurrentModificationException [duplicate]

java,collections,concurrentmodification
This question already has an answer here: Why isn't this code causing a ConcurrentModificationException? 4 answers I wrote this example following a test ConcurrentModificationException concept: public class Person { String name; public Person(String name) { this.name = name; } } public static void main(String[] args) { List<Person> l =...

Concurrent Access within a Big InMemory B+Index

java,multithreading,concurrency,b-tree,concurrentmodification
I am currently designing around a big memory index structure (several giga bytes). The index is actually a RTree which leafes are BTrees (dont ask). It supports a special query and pushes it to the logical limit. Since those nodes are soley search nodes I ask my self how to...

Behavior of entrySet().removeIf in ConcurrentHashMap

java,multithreading,java.util.concurrent,concurrenthashmap,concurrentmodification
I would like to use ConcurrentHashMap to let one thread delete some items from the map periodically and other threads to put and get items from the map at the same time. I'm using map.entrySet().removeIf(lambda) in the removing thread. I'm wondering what assumptions I can make about its behavior. I...

ConcurrentModificationException when removing item in nested loops

java,loops,nested,concurrentmodification
This is my code, and I obtained a ConcurrentModificationException when I removed an element. I do not understand why itrGrupo1 is affected by removing an element in itrGrupo2. The exception occurs at: Instancia inst1=(Instancia) itrGrupo1.next() when the second while is finished. for (int i=0; i<lstPrimeraAgrupacion.size();i++){ List grupo1=new ArrayList(); List grupo2=new...

Does the HashMap class have an Iterator to prevent a ConcurrentModificationException from being thrown? [duplicate]

java,dictionary,concurrentmodification
This question already has an answer here: iterating over and removing from a map 11 answers The following piece of code, while executed by a single thread, throws a ConcurrentModificationException on line 4: Map<String, String> map = new HashMap<String, String>(); map.put("key1", "value1"); map.put("key2", "value2"); for (String key : map.keySet())...

Java Concurrency Issues concerning Listeners

java,vector,concurrency,concurrentmodification
What is the best, or the common solution to concurrency concerning Java? I see a lot of solutions on this and other websites, but none of them work for my problem. My problem is as follows: I have a vector of a class I wrote myself. (If this helps solving...

Java 8 ConcurrentModificationException when doing any kind of iteration

java,foreach,lambda,concurrentmodification
Trying to figure out this problem for 2 weeks, but without any success. :X It's occurring when I'm doing any kind of iteration, but mostly when using #forEach. I'm not modifying the list, nor it's elements, in any way, so this seems very awkward to me. Example code: Map<Season, List<Team>>...