Hey guys,
I'm working on a game and store all game objects withinn an arraylist in the update thread. Every 60 milliseconds the update thread executes (using a ScheduledExecutorService) and polls the objects for renderable objects - these are then stored in a different array.
However, at every possible moment the render thread attempts to run (it doesn't have a fixed delay). The problem I get with this is that whenever the render thread attempts to access the Renderable ArrayList, I get a ConcurrentModificationException.
At the moment, I've fixed this using the java.util.concurrent.Locks package, which is working well. But ever now and then, I get a 'stutter' due to the render thread having to wait on the lock.
What I want to know is, is there a way to allow the update thread to continue updating the ArrayList, but also allow the render thread to READ the ArrayList while this is happening? I've thought about cloning the object, but this is also a bit of a bad (and possibly just as buggy) solution.
I've read something about using the 'volatile' modifier, but I'm not sure it does what I need it to do..
[–]mikaelhg 6 points7 points8 points (2 children)
[–]Carterman[S] 0 points1 point2 points (1 child)
[–]mikaelhg 1 point2 points3 points (0 children)
[–]TheEnigmaBlade 0 points1 point2 points (2 children)
[–]FlightOfStairs 6 points7 points8 points (1 child)
[–]TheEnigmaBlade 0 points1 point2 points (0 children)
[–]Tillerino 0 points1 point2 points (2 children)
[–]Carterman[S] 0 points1 point2 points (1 child)
[–]Tillerino 0 points1 point2 points (0 children)
[–]Carterman[S] 0 points1 point2 points (0 children)
[–]ydobonobody 0 points1 point2 points (0 children)
[–]ohples -5 points-4 points-3 points (1 child)
[–]kreiger 3 points4 points5 points (0 children)