I wrote the following game server and want to provide a group function. Groups allow you to group players together who are "nearby" on the screen. In fast games, this group will change rapidly, as players will constantly move and leave their zones.
Since each player will need to listen to events from other players in the group, players will subscribe to the group. This brings me to my question. What is the appropriate data class or java collection class that you can use in this script to store a changing set of event listeners in a group? In my opinion, the number of listeners in the group rarely exceeded 20 and should be less than in most scenarios. This is a multi-threaded environment.
I plan to use CopyOnWriteArrayList
. But since there will be a reasonable amount of updates (due to a change in the subscription), is this class suitable? What other class would be useful? If you have a custom implementation using an array, etc., please share it.
source share