You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AbstractRegistryFactory have a piece of redundant code #2685
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();
}
Activity
carryxyh commentedon Oct 26, 2018
Hi, would u pls send a pr to fix this?
zonghaishang commentedon Oct 29, 2018
// Lock the registry access process to ensure a single instance of the registry
carryxyh commentedon Oct 29, 2018
Yes, but seems like the REGISTRIES field could change to hashmap.
How do u think about it? @zonghaishang
lllichen commentedon Oct 29, 2018
public static Collection<Registry> getRegistries() { return Collections.unmodifiableCollection(REGISTRIES.values()); }is REGISTRIES.values() escape ?
carryxyh commentedon Oct 29, 2018
I know.
But hashmap.values is also thread safe.
jingui123 commentedon Oct 29, 2018
so,do the issue need to be modified to hashmap?
carryxyh commentedon Oct 29, 2018
Hi, @jingui123
U can send a pr and let more people review it. They will give their suggestions.
:)
jingui123 commentedon Oct 29, 2018
ok, i will try it
carryxyh commentedon Oct 29, 2018
Thx for your issue.