You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "CoderXueXue (via GitHub)" <gi...@apache.org> on 2023/03/06 03:21:33 UTC

[GitHub] [dubbo] CoderXueXue opened a new issue, #11729: 异步调用 bug

CoderXueXue opened a new issue, #11729:
URL: https://github.com/apache/dubbo/issues/11729

   生产者:官网的例子
   ```
   @Override
       public CompletableFuture<String> sayHello(String name) {
           return CompletableFuture.supplyAsync(() -> {
               System.out.println(name);
               try {
                   Thread.sleep(5000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               System.out.println("我处理完了~~~");
               return "async response from provider:" + name;
           });
       }
   ````
   
   消费者
   ```
   public class AsyncDemoConsumer {
       public static void main(String[] args) throws IOException {
           ReferenceConfig<AsyncDemoService> reference = new ReferenceConfig<>();
           reference.setInterface(AsyncDemoService.class);
           reference.setTimeout(100000);
   
           DubboBootstrap start = DubboBootstrap.getInstance()
                   .application("demo-consumer") // 应用配置
                   .registry(getZookeeperRegistry()) // 注册中心配置
                   .reference(reference)
                   .start();// 启动Dubbo
   
   
   //        ExecutorService executorService = Executors.newFixedThreadPool(1);
   //        executorService.submit(() -> {
               AsyncDemoService asyncDemoService = start.getCache().get(reference);
               CompletableFuture<String> hello = asyncDemoService.sayHello("hello");
               hello(hello);
               System.out.println("---------------------------------------------");
   //        });
   //        System.in.read();
       }
   
       private static void hello(CompletableFuture<String> hello) {
           System.out.println("我做一些事情");
           hello.whenCompleteAsync((v, e) -> {
               System.out.println("他做完了");
               if (e != null) {
                   e.printStackTrace();
                   return;
               }
               System.out.println("return" + v);
           });
   
           System.out.println("我事情做完了");
       }
   }
   ```
   
   当主线程结束后,返回之后将会报错,但是我使用业务线程将不会有问题,是我理解CompletableFuture有问题,还是Bug。
   ![image](https://user-images.githubusercontent.com/63384492/223012125-f3cea7b0-c142-42de-b018-18e1128197d2.png)
   
   
   当我使用线程池,或者阻塞后主线程将不会出问题。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


Re: [I] 异步调用 消费者主线程关闭后,当生产者返回后,消费者将会报错。 [dubbo]

Posted by "CrazyHZM (via GitHub)" <gi...@apache.org>.
CrazyHZM closed issue #11729: 异步调用 消费者主线程关闭后,当生产者返回后,消费者将会报错。
URL: https://github.com/apache/dubbo/issues/11729


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [dubbo] AlbumenJ commented on issue #11729: 异步调用 消费者主线程关闭后,当生产者返回后,消费者将会报错。

Posted by "AlbumenJ (via GitHub)" <gi...@apache.org>.
AlbumenJ commented on issue #11729:
URL: https://github.com/apache/dubbo/issues/11729#issuecomment-1455980411

   > 当我使用线程池,或者阻塞后主线程将不会出问题。
   
   因为主进程结束后会开始销毁资源,未结束的请求会直接中断


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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