diff --git a/android/sdk/src/main/java/com/taobao/weex/bridge/WXServiceManager.java b/android/sdk/src/main/java/com/taobao/weex/bridge/WXServiceManager.java index 27bfb5a35f..7b052ccd0d 100644 --- a/android/sdk/src/main/java/com/taobao/weex/bridge/WXServiceManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/bridge/WXServiceManager.java @@ -24,10 +24,11 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class WXServiceManager { - private static Map sInstanceJSServiceMap = new HashMap<>(); + private static volatile ConcurrentHashMap sInstanceJSServiceMap = new ConcurrentHashMap<>(); public static boolean registerService(String name, String serviceScript, Map options) { if (TextUtils.isEmpty(name) || TextUtils.isEmpty(serviceScript)) return false; @@ -83,14 +84,16 @@ public static WXJSService getService(String serviceName) { } public static void reload() { - WXBridgeManager.getInstance().post(new Runnable() { - @Override - public void run() { - for (Map.Entry entry : sInstanceJSServiceMap.entrySet()) { - WXJSService service = entry.getValue(); - registerService(service.getName(), service.getScript(), service.getOptions()); + if(sInstanceJSServiceMap != null && sInstanceJSServiceMap.size() > 0) { + WXBridgeManager.getInstance().post(new Runnable() { + @Override + public void run() { + for (Map.Entry entry : sInstanceJSServiceMap.entrySet()) { + WXJSService service = entry.getValue(); + registerService(service.getName(), service.getScript(), service.getOptions()); + } } - } - }); + }); + } } }