haoyann commented on a change in pull request #9261:
URL: https://github.com/apache/dubbo/pull/9261#discussion_r748684356



##########
File path: 
dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
##########
@@ -613,10 +614,16 @@ private void filterEnabledInstances(Collection<Instance> 
instances) {
     }
 
     private class RegistryChildListenerImpl implements EventListener {
-        private RegistryNotifier notifier;
+        private final RegistryNotifier notifier;
+
+        private final String serviceName;
+
+        private final URL consumerUrl;
 
         public RegistryChildListenerImpl(String serviceName, URL consumerUrl, 
NotifyListener listener) {
-            notifier = new RegistryNotifier(getUrl(), 
NacosRegistry.this.getDelay()) {
+            this.serviceName = serviceName;

Review comment:
       应该考虑避免少创建 `RegistryChildListenerImpl` , 因为 `RegistryNotifier` 
会创建一个`ScheduledExecutorService` 
   ```
           if (scheduler == null) {
               this.scheduler = 
((ExecutorRepository)registryUrl.getOrDefaultApplicationModel().getExtensionLoader(ExecutorRepository.class).getDefaultExtension()).getRegistryNotificationExecutor();
           } else {
               this.scheduler = scheduler;
           }
   ```
   可以参考 `ZookeeperRegistry` 将其缓存起来,避免重复创建 `RegistryChildListenerImpl` 。
   ```
   private final ConcurrentMap<URL, ConcurrentMap<NotifyListener, 
ChildListener>> zkListeners = new ConcurrentHashMap();
   ```
   




-- 
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]

Reply via email to