ConcurrentModificationException
hey guys,,
I have been working on a server and after doing some testing I found out that it gives me ConcurrentModificationException when many users are joining at the same time.
my error comes from for(User us: room.getUsers) in this method:
private void addToRoom(User user, Room room){
for(User us: room.getUsers()){
send(us, Events.onUserEnteredRoom, userToString(user));
}
user.setRoom(room);
room.addUser(user);
}
room.getUsers() returns a set. The problems seems to be that later line room.addUser(user); is modifying the set while i am iterating if i have too many clients join at the same time. But if i synchronized users in my addUsers method why would that be a problem? :
public void addUser(User u)
{
synchronized(users){
users.add(u);
}
}
I would appreciate if someone could tell me why i am getting the error still.

