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; }