From b17ecb4555f2e9f626bc22d9c531e5740f858452 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 26 Dec 2014 21:25:28 +0100 Subject: [PATCH] Use standard manager pattern in PingManager - No need to use a synchronized map, as the getInstanceFor method is synchronized - Put the PingManager in the map where it's created and not in the constructor --- .../main/java/org/jivesoftware/smackx/ping/PingManager.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java index 996220f96..6c9997d0b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/ping/PingManager.java @@ -60,8 +60,7 @@ import org.jivesoftware.smackx.ping.packet.Ping; public class PingManager extends Manager { private static final Logger LOGGER = Logger.getLogger(PingManager.class.getName()); - private static final Map INSTANCES = Collections - .synchronizedMap(new WeakHashMap()); + private static final Map INSTANCES = new WeakHashMap(); private static final PacketFilter PING_PACKET_FILTER = new AndFilter( new PacketTypeFilter(Ping.class), IQTypeFilter.GET); @@ -86,6 +85,7 @@ public class PingManager extends Manager { PingManager pingManager = INSTANCES.get(connection); if (pingManager == null) { pingManager = new PingManager(connection); + INSTANCES.put(connection, pingManager); } return pingManager; } @@ -119,7 +119,6 @@ public class PingManager extends Manager { new SmackExecutorThreadFactory(connection.getConnectionCounter(), "Ping")); ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection); sdm.addFeature(Ping.NAMESPACE); - INSTANCES.put(connection, this); connection.addPacketListener(new PacketListener() { // Send a Pong for every Ping