I have an ArrayList in my game to store all the particles ingame. I have an update mehtod which accesses the ArrayList to update the physics, I have a render method that accesses the ArrayList to render the particles onscreen and a MouseClick listener that when it detects a MouseClick it will add a new Particle to the ArrayList.
My problem is I keep getting an java.util.ConcurrentModificationException. This is because when I click at the same time it renders and both methods are trying to access the ArrayList. Is there a solution to accessing the ArrayList at the same time (different data type?).
Solution to Concurrent Modification of a variable. ArrayList & MouseListener
Started by liamzebedee, Apr 30 2011 06:44 PM
2 replies to this topic
#1
Posted 30 April 2011 - 06:44 PM
|
|
|
#2
Posted 30 April 2011 - 08:25 PM
Vectors are threadsafe.
So, Vector is probably a better data structure to use if you know multiple threads are going to be accessing/altering your data.
So, Vector is probably a better data structure to use if you know multiple threads are going to be accessing/altering your data.
Edited by lethalwire, 30 April 2011 - 09:07 PM.
#3
Posted 30 April 2011 - 11:53 PM
You can keep your arrayList but do this on it: Collections (Java 2 Platform SE v1.4.2))
Look for synchronizedLis(List )
Look for synchronizedLis(List )
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









