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
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();
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