java - AWS SDK - purpose of async configuration SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR
问题描述
What is the purpose of asyncConfiguration SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR
?
in which use cases should we use it?
from java doc on FUTURE_COMPLETION_EXECUTOR
, I see: Configure the executor that should be used to complete the CompletableFuture that is returned by the service clients.
I thought that subsequent calls on CompletableFuture
of async result will be executed on executor passed in FUTURE_COMPLETION_EXECUTOR
, but it’s not.
ClientAsyncConfiguration.Builder asyncConfig = ClientAsyncConfiguration.builder()
.advancedOption(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, customExecutor);
SnsAsyncClient.builder()
.asyncConfiguration(asyncConfig.build())
.build();
Example of async request:
snsAsyncClient.publish(publishRequest).thenApplyAsync(..);
解决方案
AWS 开发工具包异步请求返回CompletableFuture
. 默认情况下,在返回的实例上调用thenApply(..)
和将在诸如. 异步配置的思想是提供线程池执行器,用于后续对like和的调用。这个执行器不会被应用到方法和由于实现的原因(如果执行器没有被传入,它将被默认使用,或者我们可以将自定义执行器作为第二个方法参数传递)。whenComplete(..)
CompletableFuture
sdk-async-response-0-X
SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR
CompletableFuture
thenApply(..)
whenComplete(..)
thenApplyAsync
whenCompleteAsync
CompletableFuture
thenApplyAsync(..)
ForkJoinPool.commonPool()
snsAsyncClient.publish(publishRequest)
.thenApply(..)
.whenComplete(..);
里面的代码thenApply
,whenComplete
并将在配置的执行程序上处理SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR
。
推荐阅读
- sql - 按目标子句合并不更新所需的列
- javascript - 加载 iframe 并为就绪状态添加侦听器完成
- maven - 使用 Maven 运行集成测试 - 构建成功但测试运行 = 0
- firebase - HTTP 错误:403,启用服务的权限被拒绝 [cloudfunctions.googleapis.com]
- javascript - 怎么写更短?
- flutter - 未处理的异常:使用不包含 SignupBloc 的上下文调用 BlocProvider.of()
- vb.net - Krypton Ribbon 将项目添加到文件选项卡
- java - 在 Spring Boot 中处理 javax.validation.ConstraintViolationException
- javascript - 如何从 Array Apps 脚本中选择特定(变量)列
- c++ - 未定义对类的 vtable 的引用