This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new af041d321f add default interval for retries of saving properties 
(#10412)
af041d321f is described below

commit af041d321f50f1c6ceba693090d843dffab8ec95
Author: jk-tonycui <[email protected]>
AuthorDate: Mon Aug 15 09:59:32 2022 +0800

    add default interval for retries of saving properties (#10412)
---
 .../apache/dubbo/registry/support/AbstractRegistry.java    | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
index f72aa5877f..516a974945 100644
--- 
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
+++ 
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java
@@ -49,7 +49,8 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
@@ -79,12 +80,15 @@ public abstract class AbstractRegistry implements Registry {
     private static final String URL_SPLIT = "\\s+";
     // Max times to retry to save properties to local cache file
     private static final int MAX_RETRY_TIMES_SAVE_PROPERTIES = 3;
+    // Default interval in millisecond for saving properties to local cache 
file
+    private static final long DEFAULT_INTERVAL_SAVE_PROPERTIES = 500L;
+
     // Log output
     protected final Logger logger = LoggerFactory.getLogger(getClass());
     // Local disk cache, where the special key value.registries records the 
list of registry centers, and the others are the list of notified service 
providers
     private final Properties properties = new Properties();
     // File cache timing writing
-    private final ExecutorService registryCacheExecutor;
+    private final ScheduledExecutorService registryCacheExecutor;
     private final AtomicLong lastCacheChanged = new AtomicLong();
     private final AtomicInteger savePropertiesRetryTimes = new AtomicInteger();
     private final Set<URL> registered = new ConcurrentHashSet<>();
@@ -104,7 +108,7 @@ public abstract class AbstractRegistry implements Registry {
         registryManager = 
url.getOrDefaultApplicationModel().getBeanFactory().getBean(RegistryManager.class);
         localCacheEnabled = 
url.getParameter(REGISTRY_LOCAL_FILE_CACHE_ENABLED, true);
         registryCacheExecutor = 
url.getOrDefaultFrameworkModel().getBeanFactory()
-            .getBean(FrameworkExecutorRepository.class).getSharedExecutor();
+            
.getBean(FrameworkExecutorRepository.class).getSharedScheduledExecutor();
         if (localCacheEnabled) {
             // Start file save timer
             syncSaveFile = url.getParameter(REGISTRY_FILESAVE_SYNC_KEY, false);
@@ -238,7 +242,7 @@ public abstract class AbstractRegistry implements Registry {
                 savePropertiesRetryTimes.set(0);
                 return;
             } else {
-                registryCacheExecutor.execute(() -> 
doSaveProperties(lastCacheChanged.incrementAndGet()));
+                registryCacheExecutor.schedule(() -> 
doSaveProperties(lastCacheChanged.incrementAndGet()), 
DEFAULT_INTERVAL_SAVE_PROPERTIES, TimeUnit.MILLISECONDS);
             }
             if (!(e instanceof OverlappingFileLockException)) {
                 logger.warn("Failed to save registry cache file, will retry, 
cause: " + e.getMessage(), e);
@@ -495,7 +499,7 @@ public abstract class AbstractRegistry implements Registry {
             if (syncSaveFile) {
                 doSaveProperties(version);
             } else {
-                registryCacheExecutor.execute(() -> doSaveProperties(version));
+                registryCacheExecutor.schedule(() -> 
doSaveProperties(version), DEFAULT_INTERVAL_SAVE_PROPERTIES, 
TimeUnit.MILLISECONDS);
             }
         } catch (Throwable t) {
             logger.warn(t.getMessage(), t);

Reply via email to