I hava a problem with synchronization Where I hava npc characters in the game I keep their names in the field at ZoneExtension
Code: Select all
private Set<String> reusable_users = new HashSet<>();
when someone creates a gameroom at the RoomAdded event I start scheduler so that scheduler gets a name and find corresponding npc by findUserByName and insert it into game room problem is
Code: Select all
public String removeReusableRobot(String name){
String name_to_return = null;
synchronized (reusable_users){
if(reusable_users.contains(name)){
name_to_return = name;
reusable_users.remove(name);
//sfsExtension.trace(" Bot has been returned " + name);
}
}
return name_to_return;
}
this is in the Zone extension here synchronized doesnt work. Different threads get same name. I use synchronized method outside smartfox it never happens.
I had similar issues many times. I fixed the problem by adding a variable to npc like is_this_in use true or false.
I want to know what is causing this
I am using SmartFox 2.11
Thanks.