当CompletableFuture超出范围时会发生什么

问题描述

我对CompletableFuture的行为感到好奇,当它超出提供它的方法的范围时,该行为已设置为其他执行器。

例如,正在使用以下代码片段:

public List<String> someMethod(ExecutorService service){
   List<String> myData = this.getMyData();
   CompletableFuture.supplyAsync(() -> this.doSomethingWithMyData(myData),service)
     .thenApplyAsync(this::doSomeTransformation)
     .thenAcceptAsync(this::consumeResults)
     .orTimeout(5,TimeUnit.MINUTES);

   return myData;
}

假设这是长时间运行的并发作业,那么该方法返回后,CompletableFuture(及其异步函数链)是否仍将完全执行?假设整个应用程序仍在该时间段内运行(例如RESTful服务)。

我的直觉告诉我,方法返回后它仍然可以运行,但是我还没有看到答案,所以我希望对此猜测进行验证。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...