From c58a17897b1459bfc8220dbc784647a1b89945f1 Mon Sep 17 00:00:00 2001 From: xuhaotony Date: Fri, 19 Oct 2018 22:20:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E9=81=8D=E5=8E=86=E6=97=B6,=E7=BA=BF=E7=A8=8B=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E5=87=BA=E7=8E=B0=E4=BF=AE=E6=94=B9=E9=9B=86=E5=90=88?= =?UTF-8?q?=E5=BC=82=E5=B8=B8,=E6=9C=AA=E8=80=83=E8=99=91=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/client/action/ActionDispatcher.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/socket/src/main/java/com/xuhao/android/libsocket/impl/client/action/ActionDispatcher.java b/socket/src/main/java/com/xuhao/android/libsocket/impl/client/action/ActionDispatcher.java index e170990..b205127 100644 --- a/socket/src/main/java/com/xuhao/android/libsocket/impl/client/action/ActionDispatcher.java +++ b/socket/src/main/java/com/xuhao/android/libsocket/impl/client/action/ActionDispatcher.java @@ -24,6 +24,7 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import static com.xuhao.android.libsocket.sdk.client.action.IAction.ACTION_CONNECTION_FAILED; import static com.xuhao.android.libsocket.sdk.client.action.IAction.ACTION_CONNECTION_SUCCESS; @@ -59,7 +60,7 @@ public class ActionDispatcher implements IRegister mResponseHandlerMap = new HashMap<>(); + private ConcurrentHashMap mResponseHandlerMap = new ConcurrentHashMap<>(); /** * 上下文 */ @@ -118,9 +119,7 @@ public void onReceive(Context context, Intent intent) { ACTION_WRITE_THREAD_SHUTDOWN, ACTION_WRITE_THREAD_START, ACTION_PULSE_REQUEST); - synchronized (mResponseHandlerMap) { - mResponseHandlerMap.put(socketResponseHandler, broadcastReceiver); - } + mResponseHandlerMap.put(socketResponseHandler, broadcastReceiver); } } return mManager; @@ -133,11 +132,9 @@ private IConnectionManager unRegisterReceiver(BroadcastReceiver broadcastReceive @Override public IConnectionManager unRegisterReceiver(ISocketActionListener socketResponseHandler) { - synchronized (mResponseHandlerMap) { - BroadcastReceiver broadcastReceiver = mResponseHandlerMap.get(socketResponseHandler); - mResponseHandlerMap.remove(socketResponseHandler); - unRegisterReceiver(broadcastReceiver); - } + BroadcastReceiver broadcastReceiver = mResponseHandlerMap.get(socketResponseHandler); + mResponseHandlerMap.remove(socketResponseHandler); + unRegisterReceiver(broadcastReceiver); return mManager; }