AlbumenJ commented on a change in pull request #8701:
URL: https://github.com/apache/dubbo/pull/8701#discussion_r706614955
##########
File path:
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java
##########
@@ -246,12 +246,17 @@ private void refreshInvoker(List<URL> invokerUrls) {
destroyAllInvokers(); // Close all invokers
} else {
this.forbidden = false; // Allow accessing
- Map<String, Invoker<T>> oldUrlInvokerMap = this.urlInvokerMap; //
local reference
if (CollectionUtils.isEmpty(invokerUrls)) {
return;
}
- Map<String, Invoker<T>> newUrlInvokerMap =
toInvokers(invokerUrls);// Translate url list to Invoker map
+ // can't use local reference because this.urlInvokerMap might be
accessed at isAvailable() by main thread concurrently.
+ Map<String, Invoker<T>> oldUrlInvokerMap = null;
+ if (this.urlInvokerMap != null) {
+ oldUrlInvokerMap = new HashMap<>();
Review comment:
it would be better to sepcify the default size for HashMap here
##########
File path:
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
##########
@@ -216,7 +216,14 @@ private void refreshInvoker(List<URL> invokerUrls) {
if (invokerUrls.isEmpty()) {
return;
}
- Map<URL, Invoker<T>> newUrlInvokerMap = toInvokers(invokerUrls);//
Translate url list to Invoker map
+
+ // can't use local reference because this.urlInvokerMap might be
accessed at isAvailable() by main thread concurrently.
+ Map<URL, Invoker<T>> oldUrlInvokerMap = null;
+ if (this.urlInvokerMap != null) {
+ oldUrlInvokerMap = new HashMap<>();
Review comment:
also for there
##########
File path:
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java
##########
@@ -246,12 +246,17 @@ private void refreshInvoker(List<URL> invokerUrls) {
destroyAllInvokers(); // Close all invokers
} else {
this.forbidden = false; // Allow accessing
- Map<String, Invoker<T>> oldUrlInvokerMap = this.urlInvokerMap; //
local reference
if (CollectionUtils.isEmpty(invokerUrls)) {
return;
}
- Map<String, Invoker<T>> newUrlInvokerMap =
toInvokers(invokerUrls);// Translate url list to Invoker map
+ // can't use local reference because this.urlInvokerMap might be
accessed at isAvailable() by main thread concurrently.
+ Map<String, Invoker<T>> oldUrlInvokerMap = null;
+ if (this.urlInvokerMap != null) {
+ oldUrlInvokerMap = new HashMap<>();
Review comment:
using LinkedHashMap will reduce temporally memery usage when using
iterator in forEach
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]