Skip to content

Commit bff4bcf

Browse files
committed
Support concurrent loading of Config for different namespaces (#29)
1 parent 265fe49 commit bff4bcf

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ Apollo Java 2.2.0
77
------------------
88
[refactor(apollo-client): Optimize the exception message when failing to retrieve configuration information.](https://github.com/apolloconfig/apollo-java/pull/22)
99
[Add JUnit5 extension support for apollo mock server.](https://github.com/apolloconfig/apollo-java/pull/25)
10+
[Support concurrent loading of Config for different namespaces.](https://github.com/apolloconfig/apollo-java/pull/31)
1011
------------------
1112
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/2?closed=1)

apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public class DefaultConfigManager implements ConfigManager {
3333
private ConfigFactoryManager m_factoryManager;
3434

3535
private Map<String, Config> m_configs = Maps.newConcurrentMap();
36+
private Map<String, Object> m_configLocks = Maps.newConcurrentMap();
3637
private Map<String, ConfigFile> m_configFiles = Maps.newConcurrentMap();
38+
private Map<String, Object> m_configFileLocks = Maps.newConcurrentMap();
3739

3840
public DefaultConfigManager() {
3941
m_factoryManager = ApolloInjector.getInstance(ConfigFactoryManager.class);
@@ -44,7 +46,8 @@ public Config getConfig(String namespace) {
4446
Config config = m_configs.get(namespace);
4547

4648
if (config == null) {
47-
synchronized (this) {
49+
Object lock = m_configLocks.computeIfAbsent(namespace, key -> new Object());
50+
synchronized (lock) {
4851
config = m_configs.get(namespace);
4952

5053
if (config == null) {
@@ -65,7 +68,8 @@ public ConfigFile getConfigFile(String namespace, ConfigFileFormat configFileFor
6568
ConfigFile configFile = m_configFiles.get(namespaceFileName);
6669

6770
if (configFile == null) {
68-
synchronized (this) {
71+
Object lock = m_configFileLocks.computeIfAbsent(namespaceFileName, key -> new Object());
72+
synchronized (lock) {
6973
configFile = m_configFiles.get(namespaceFileName);
7074

7175
if (configFile == null) {

0 commit comments

Comments
 (0)