Fix service was offline without re-registration due to network jitter (#10182)
This commit is contained in:
parent
9efe21af84
commit
d6460f53c6
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue