Skip to content

Commit

Permalink
修复因网络抖动导致服务长时间下线没有重新注册的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
icodening committed Jun 20, 2022
1 parent 9efe21a commit d4e1e09
Showing 1 changed file with 23 additions and 1 deletion.
Expand Up @@ -46,6 +46,9 @@
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;
Expand Down Expand Up @@ -296,6 +299,15 @@ public void nodeChanged() throws Exception {

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;
Expand All @@ -322,7 +334,17 @@ public void process(WatchedEvent event) throws Exception {
}

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);
}
}
}
Expand Down

0 comments on commit d4e1e09

Please sign in to comment.