I have two threads.
the main thread and the rendering thread.
the main thread constantly iterates through my entities lists and makes them think and does game logic, etc..
the rendering thread constantly iterates through the entities list and renders them
in my main thread, I put in some code that would delete an entity after such and such occurred. however, there is a random chance that this throws a concurrent modification exception with my rendering thread, and I was wondering on what I should do to avoid this?
I'm using the synchronization keywords, but it's possible that I'm just not using them correctly to fit my situation. My understanding is that two synchronized methods/blocks cannot run concurrently.
public void RemoveEntity( Entity e ) { synchronized( e ) { entList.remove( e ); } } public synchronized void Draw( GL10 gl ) { Iterator itr = entList.iterator(); while( itr.hasNext() ) { Entity e = ( Entity )itr.next(); ( e ).Draw( gl ); }