You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/08/08 01:11:48 UTC

[GitHub] chickenlj commented on a change in pull request #2213: [Dubbo-2187] Use CompletetableFuture to rewrite the embedded ListenableFuture

chickenlj commented on a change in pull request #2213: [Dubbo-2187] Use CompletetableFuture to rewrite the embedded ListenableFuture
URL: https://github.com/apache/incubator-dubbo/pull/2213#discussion_r208430472
 
 

 ##########
 File path: dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/zkclient/ZkClientWrapper.java
 ##########
 @@ -43,28 +41,26 @@
     private long timeout;
     private ZkClient client;
     private volatile KeeperState state;
-    private ListenableFutureTask<ZkClient> listenableFutureTask;
+    private CompletableFuture<ZkClient> completableFuture;
     private volatile boolean started = false;
+    private static final ExecutorService executor = new ThreadPoolExecutor(0, 10, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("DubboMonitorCreator", true));
 
 
     public ZkClientWrapper(final String serverAddr, long timeout) {
         this.timeout = timeout;
-        listenableFutureTask = ListenableFutureTask.create(new Callable<ZkClient>() {
-            @Override
-            public ZkClient call() throws Exception {
+        completableFuture = CompletableFuture.supplyAsync(()->{
                 return new ZkClient(serverAddr, Integer.MAX_VALUE);
-            }
-        });
+        },executor);
     }
 
     public void start() {
         if (!started) {
-            Thread connectThread = new Thread(listenableFutureTask);
+            Thread connectThread = new Thread();
 
 Review comment:
   I think `Thread connectThread = new Thread();` is no longer needed here, because we already started `ZkClient` in an async thread by invoking `CompletableFuture.supplyAsync`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org