From 49c8b83e52be90d04619d26b69223fc47b25df7a Mon Sep 17 00:00:00 2001 From: Tux Date: Fri, 18 Oct 2013 17:11:24 -0400 Subject: [PATCH] Get a fresh resource each time instead. --- .../redisbungee/UpdateCountTask.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/UpdateCountTask.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/UpdateCountTask.java index 1d22bc2..4960e33 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/UpdateCountTask.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/UpdateCountTask.java @@ -11,31 +11,30 @@ import redis.clients.jedis.Jedis; public class UpdateCountTask implements Runnable { private RedisBungee plugin; - private Jedis rsc; private boolean kill = false; public UpdateCountTask(RedisBungee plugin) { this.plugin = plugin; - rsc = plugin.getPool().getResource(); } @Override public void run() { if (kill) { - if (rsc != null) { - plugin.getPool().returnResource(rsc); - rsc = null; - } return; } - int c = plugin.getProxy().getOnlineCount(); - rsc.set("server:" + plugin.getServerId() + ":playerCount", String.valueOf(c)); - for (String i : plugin.getServers()) { - if (i.equals(plugin.getServerId())) continue; - if (rsc.exists("server:" + i + ":playerCount")) - c += Integer.valueOf(rsc.get("server:" + i + ":playerCount")); + Jedis rsc = plugin.getPool().getResource(); + try { + int c = plugin.getProxy().getOnlineCount(); + rsc.set("server:" + plugin.getServerId() + ":playerCount", String.valueOf(c)); + for (String i : plugin.getServers()) { + if (i.equals(plugin.getServerId())) continue; + if (rsc.exists("server:" + i + ":playerCount")) + c += Integer.valueOf(rsc.get("server:" + i + ":playerCount")); + } + plugin.setCount(c); + } finally { + plugin.getPool().returnResource(rsc); } - plugin.setCount(c); } protected void kill() {