Fix service was offline without re-registration due to network jitter (#10182)

This commit is contained in:
一个不知名的Java靓仔 2022-06-22 16:57:34 +08:00 committed by GitHub
parent 9efe21af84
commit d6460f53c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 1 deletions

View File

@ -46,6 +46,9 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
@ -296,6 +299,15 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
static class CuratorWatcherImpl implements CuratorWatcher {
private static final ExecutorService CURATOR_WATCHER_EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setName("Dubbo-CuratorWatcher-Thread");
return thread;
}
});
private CuratorFramework client;
private volatile ChildListener childListener;
private String path;
@ -322,7 +334,17 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
}
if (childListener != null) {
childListener.childChanged(path, client.getChildren().usingWatcher(this).forPath(path));
Runnable task = new Runnable() {
@Override
public void run() {
try {
childListener.childChanged(path, client.getChildren().usingWatcher(CuratorWatcherImpl.this).forPath(path));
} catch (Exception e) {
logger.warn("client get children error", e);
}
}
};
CURATOR_WATCHER_EXECUTOR_SERVICE.execute(task);
}
}
}