Skip to content

Commit

Permalink
Support concurrent loading of Config for different namespaces (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
zth9 authored and nobodyiam committed Aug 13, 2023
1 parent 265fe49 commit e4d12c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ Apollo Java 2.2.0
------------------
[refactor(apollo-client): Optimize the exception message when failing to retrieve configuration information.](https://github.com/apolloconfig/apollo-java/pull/22)
[Add JUnit5 extension support for apollo mock server.](https://github.com/apolloconfig/apollo-java/pull/25)
[Support concurrent loading of Config for different namespaces.](https://github.com/apolloconfig/apollo-java/pull/31)
------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/2?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public class DefaultConfigManager implements ConfigManager {
private ConfigFactoryManager m_factoryManager;

private Map<String, Config> m_configs = Maps.newConcurrentMap();
private Map<String, Object> m_configLocks = Maps.newConcurrentMap();
private Map<String, ConfigFile> m_configFiles = Maps.newConcurrentMap();
private Map<String, Object> m_configFileLocks = Maps.newConcurrentMap();

public DefaultConfigManager() {
m_factoryManager = ApolloInjector.getInstance(ConfigFactoryManager.class);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit e4d12c7

Please sign in to comment.