From f351a6a629eecf39cc6bf5bed7f5777f9b35ee49 Mon Sep 17 00:00:00 2001 From: tian90coder Date: Fri, 11 Aug 2023 10:59:45 +0800 Subject: [PATCH] Support concurrent loading of Config for different namespaces (#29) --- .../framework/apollo/internals/DefaultConfigManager.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java index f583a915..e897b6f7 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java @@ -33,7 +33,9 @@ public class DefaultConfigManager implements ConfigManager { private ConfigFactoryManager m_factoryManager; private Map m_configs = Maps.newConcurrentMap(); + private Map m_configLocks = Maps.newConcurrentMap(); private Map m_configFiles = Maps.newConcurrentMap(); + private Map m_configFileLocks = Maps.newConcurrentMap(); public DefaultConfigManager() { m_factoryManager = ApolloInjector.getInstance(ConfigFactoryManager.class); @@ -44,7 +46,8 @@ public Config getConfig(String namespace) { Config config = m_configs.get(namespace); if (config == null) { - synchronized (this) { + Object lock = m_configLocks.computeIfAbsent(namespace, key -> new Object()); + synchronized (lock) { config = m_configs.get(namespace); if (config == null) { @@ -65,7 +68,8 @@ public ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFor ConfigFile configFile = m_configFiles.get(namespaceFileName); if (configFile == null) { - synchronized (this) { + Object lock = m_configFileLocks.computeIfAbsent(namespaceFileName, key -> new Object()); + synchronized (lock) { configFile = m_configFiles.get(namespaceFileName); if (configFile == null) {