Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Java have a data structure that supports Concurrent Modification?

I'm making a game in Java. Every enemy in the game is a thread and they are constantly looping through the game's data structures (I always use the class Vector).

Lately I have been getting the "ConcurrentModificationException" because an element is being added/removed from a Vector while a Thread is looping through it. I know there are strategies to avoid the add/remove problem (I actually use some to avoid problems with Removes but I still have problems with "Adds").

I heard that java supports a Vector/List that avoids the ConcurrentModificationException.

Do you have any idea of what this structure might be? Thanks.

like image 428
Rama Avatar asked May 23 '26 09:05

Rama


1 Answers

Check out java.util.concurrent, it has what you're looking for.

like image 157
Matt Fenwick Avatar answered May 26 '26 07:05

Matt Fenwick