I'm using a Map object in my class that I've synchronized with Collections.synchronizedMap() for a LinkedHashMap like so:
private GameObjectManager(){
gameObjects = Collections.synchronizedMap(new LinkedHashMap<String, GameObject>());
}
I'm getting a concurrent modification exception on the third line of this function:
public static void frameElapsed(float msElapsed){
if(!INSTANCE.gameObjects.isEmpty()){
synchronized(INSTANCE.gameObjects){
for(GameObject object : INSTANCE.gameObjects.values()){...}
}
}
}
All other locations where I am iterating through the Map, I am synchronizing on the map per the docs.
There are other functions in my class that use this Map (the synchronized one!) and they put() and remove() objects, but this shouldn't matter though. What am I doing wrong? Please ask for more code, not sure what else to put.
Oh, and the log message:
08-20 15:55:30.109: E/AndroidRuntime(14482): FATAL EXCEPTION: GLThread 1748
08-20 15:55:30.109: E/AndroidRuntime(14482): java.util.ConcurrentModificationException
08-20 15:55:30.109: E/AndroidRuntime(14482): at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:350)
08-20 15:55:30.109: E/AndroidRuntime(14482): at java.util.LinkedHashMap$ValueIterator.next(LinkedHashMap.java:374)
08-20 15:55:30.109: E/AndroidRuntime(14482): at package.GameObjectManager.frameElapsed(GameObjectManager.java:247)
08-20 15:55:30.109: E/AndroidRuntime(14482): at package.GamekitInterface.render(Native Method)
08-20 15:55:30.109: E/AndroidRuntime(14482): at package.GamekitInterface.renderFrame(GamekitInterface.java:332)
08-20 15:55:30.109: E/AndroidRuntime(14482): at com.qualcomm.QCARSamples.ImageTargets.GameEngineInterface.onDrawFrame(GameEngineInterface.java:107)
08-20 15:55:30.109: E/AndroidRuntime(14482): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516)
08-20 15:55:30.109: E/AndroidRuntime(14482): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)