?????????????С???????????????????????????????????? ???????????????????????GameServer??this????????????????????(leave)??????????????????????????????????????????????????????????????????????????С?????????????
??????С??????????
??????????????????????????????????????????????????????????????????——????????????????д?????? ??

 

public class GameServer {
public Map<String?? List<Player>> tables = new HashMap<String?? List<Player>>();
public void join(Player player?? Table table) {
if (player.getAccountBalance() > table.getLimit()) {
synchronized (tables) {
List<Player> tablePlayers = tables.get(table.getId());
if (tablePlayers.size() < 9) {
tablePlayers.add(player);
}
}
}
}
//other methods skipped for brevity
}

????????????????????????????????????????????????????????????????????????????????????????????????????????????????鰱????????????Χ????
?????????
???????????????δ?????????????????????????????????????????????????????п??????????????????????????????????????????????????????????????????????????????С?
????????????????????????????????????????????????£????????£?

 

public class GameServer {
public Map<String?? List<Player>> tables = new HashMap<String?? List<Player>>();
public void join(Player player?? Table table) {
if (player.getAccountBalance() > table.getLimit()) {
List<Player> tablePlayers = tables.get(table.getId());
synchronized (tablePlayers) {
if (tablePlayers.size() < 9) {
tablePlayers.add(player);
}
}
}
}
//other methods skipped for brevity
}

??????????????????????????????????????????????????????????????????????????С???????????????100????????????????????????????С??100????
??????ò??????????
?????????????????????????????????????????????????????????????????????????????????ConcurrentHashMap???洢???е?????????????????????????

 

public class GameServer {
public Map<String?? List<Player>> tables = new ConcurrentHashMap<String?? List<Player>>();
public synchronized void join(Player player?? Table table) {/*Method body skipped for brevity*/}
public synchronized void leave(Player player?? Table table) {/*Method body skipped for brevity*/}
public synchronized void createTable() {
Table table = new Table();
tables.put(table.getId()?? table);
}
public synchronized void destroyTable(Table table) {
tables.remove(table.getId());
}
}

????join()??leave()???????????????????????????????????????tables???м?????????????ConcurrentHashMap?????????????????????tablePlayers?????????????????ConcurrentHashMap????????????????????createTable()??destroyTable()?????д????μ????????????????????ConcurrentHashMap?????????????????????????е??????????????????????
??????????????????
????????????????????????????У??????????public????????????????????????????????????????????????????????????????
?????????java.util.concurrent.locks??????????Щ????????????а??????
???????????????????????????е??????????????????????м?????????????Integer????AtomicInteger?????????????′????????