Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractRegistryFactory have a piece of redundant code #2685

Closed
jingui123 opened this issue Oct 24, 2018 · 9 comments
Closed

AbstractRegistryFactory have a piece of redundant code #2685

jingui123 opened this issue Oct 24, 2018 · 9 comments

Comments

@jingui123
Copy link
Contributor

I have found a piece of redundant code, may be is I do not understand.
in AbstractRegistryFactory class, there are two variables,one is LOCK,the other is REGISTRIES,as follows :
private static final ReentrantLock LOCK = new ReentrantLock();

// Registry Collection Map<RegistryAddress, Registry>
private static final Map<String, Registry> REGISTRIES = new ConcurrentHashMap<String, Registry>();

but when we use REGISTRIES.put() , the section of code is locked. so I think REGISTRIES will be better to modify HashMap.
example:
public Registry getRegistry(URL url) {
....
LOCK.lock();
REGISTRIES.put(key, registry);
LOCK.unlock();
}
public static void destroyAll() {
....
LOCK.lock();
REGISTRIES.clear();
LOCK.unlock();
}

Environment

  • Dubbo version: 2.7.0-SNAPSHOT
  • Java version: jdk1.8
@carryxyh
Copy link
Member

Hi, would u pls send a pr to fix this?

@zonghaishang
Copy link
Member

// Lock the registry access process to ensure a single instance of the registry

@carryxyh
Copy link
Member

Yes, but seems like the REGISTRIES field could change to hashmap.
How do u think about it? @zonghaishang

@lllichen
Copy link
Contributor

lllichen commented Oct 29, 2018

public static Collection<Registry> getRegistries() { return Collections.unmodifiableCollection(REGISTRIES.values()); }
is REGISTRIES.values() escape ?

@carryxyh
Copy link
Member

I know.
But hashmap.values is also thread safe.

@jingui123
Copy link
Contributor Author

so,do the issue need to be modified to hashmap?

@carryxyh
Copy link
Member

carryxyh commented Oct 29, 2018

Hi, @jingui123
U can send a pr and let more people review it. They will give their suggestions.
:)

@jingui123
Copy link
Contributor Author

ok, i will try it

@carryxyh
Copy link
Member

Thx for your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants