From 0721e3cc751e98250954cf5a68df54269dc4aa07 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 31 Jan 2013 17:55:46 +1100 Subject: [PATCH] Sweet trick to avoid locking in global tab list, basically reimplement HashSet based on a ConcurrentHashMap. --- .../net/md_5/bungee/tablist/GlobalTabList.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalTabList.java b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalTabList.java index b622e27c..b563ebd1 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalTabList.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalTabList.java @@ -1,8 +1,7 @@ package net.md_5.bungee.tablist; -import java.util.HashSet; -import java.util.Set; -import lombok.Synchronized; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.ProxyServer; @@ -13,7 +12,9 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem; public class GlobalTabList implements TabListHandler { - private final Set sentPings = new HashSet<>(); + // Sweet trick to avoid locking, basically reimplement HashSet based on a ConcurrentHashMap + private static final Object PRESENT = new Object(); + private final Map sentPings = new ConcurrentHashMap<>(); @Override public void onConnect(ProxiedPlayer player) @@ -27,18 +28,16 @@ public class GlobalTabList implements TabListHandler } @Override - @Synchronized(value = "sentPings") public void onPingChange(ProxiedPlayer player, int ping) { - if (!sentPings.contains(player)) + if (!sentPings.containsKey(player)) { BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, player.getPing())); - sentPings.add(player); + sentPings.put(player, PRESENT); } } @Override - @Synchronized(value = "sentPings") public void onDisconnect(ProxiedPlayer player) { BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999));