diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java index 30595f9dbbd..5f5931a63ea 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java @@ -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; @@ -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; @@ -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); } } }