You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "QiuYucheng2003 (via GitHub)" <gi...@apache.org> on 2026/01/09 08:27:50 UTC

Re: [PR] [Fix-15886] Fix thread leak in NacosRegistry using Double-Checked Locking [dubbo]

QiuYucheng2003 commented on code in PR #15915:
URL: https://github.com/apache/dubbo/pull/15915#discussion_r2675289947


##########
dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java:
##########
@@ -473,26 +473,30 @@ private boolean isAdminProtocol(URL url) {
 
     private void scheduleServiceNamesLookup(final URL url, final NacosAggregateListener listener) {
         if (scheduledExecutorService == null) {
-            scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
-            scheduledExecutorService.scheduleAtFixedRate(
-                    () -> {
-                        Set<String> serviceNames = getAllServiceNames();
-                        filterData(serviceNames, serviceName -> {
-                            boolean accepted = false;
-                            for (String category : ALL_SUPPORTED_CATEGORIES) {
-                                String prefix = category + SERVICE_NAME_SEPARATOR;
-                                if (serviceName != null && serviceName.startsWith(prefix)) {
-                                    accepted = true;
-                                    break;
-                                }
-                            }
-                            return accepted;
-                        });
-                        doSubscribe(url, listener, serviceNames);
-                    },
-                    LOOKUP_INTERVAL,
-                    LOOKUP_INTERVAL,
-                    TimeUnit.SECONDS);
+            synchronized (this) {
+                if (scheduledExecutorService == null) {
+                    scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

Review Comment:
   Verified that scheduledExecutorService is declared as volatile, so this DCL pattern is thread-safe.



-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org