??????????
?????????????????????д??????????????????????????????????????????????????????????п????????????????????????????????κ?????????????????????????????????????????????к?????????????????
???????????????????????????????????????????????????????????????
????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()????????????????????????????????????????????????????????????????ConcurrentHashMap ????????????κ???????????????????increateTable()??destoryTable()?????????ConcurrentHashMap???????????μ?????????????Щ????????ConcurrentHashMap????????????????????????????е??????????????????????
?????????Щ????????
?????????????????????????????У??????????public??????????????????????Щ???????????????????????????????????????????????
?????????java.util.concurrent.locks ??API??????? ???????????????????????????????????????????
??????????????????????????????????????????????????????????????????и??????? AtomicInteger????Integer???????????
?????????????????????????Plumber?????????????????????????????????????y????????????????????????????????????????????????????