为了账号安全,请及时绑定邮箱和手机立即绑定

AWS SDK - 异步配置的目的 SdkAdvancedAsyncClientOption.

AWS SDK - 异步配置的目的 SdkAdvancedAsyncClientOption.

幕布斯6054654 2023-03-23 16:17:55
asyncConfiguration 的目的是什么 SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR?我们应该在哪些用例中使用它?从 java doc 上FUTURE_COMPLETION_EXECUTOR,我看到:Configure the executor that should be used to complete the CompletableFuture that is returned by the service clients.我认为后续对CompletableFuture异步结果的调用将在传入的执行程序上执行FUTURE_COMPLETION_EXECUTOR,但事实并非如此。ClientAsyncConfiguration.Builder asyncConfig = ClientAsyncConfiguration.builder()        .advancedOption(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, customExecutor);SnsAsyncClient.builder()        .asyncConfiguration(asyncConfig.build())        .build();异步请求示例:snsAsyncClient.publish(publishRequest).thenApplyAsync(..);
查看完整描述

1 回答

?
www说

TA贡献1775条经验 获得超8个赞

AWS SDK 异步请求返回CompletableFuture。默认情况下,对返回实例的调用thenApply(..)和对返回实例的调用将在类似线程上执行。async配置的思路是提供线程池executor,用于后续对like和 的调用。该执行器将不会应用于像和由于实现这样的方法(如果未将执行器传递给,它将默认使用,或者我们可以将自定义执行器作为第二个方法参数传递)。whenComplete(..)CompletableFuturesdk-async-response-0-XSdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTORCompletableFuturethenApply(..)whenComplete(..)thenApplyAsyncwhenCompleteAsyncCompletableFuturethenApplyAsync(..)ForkJoinPool.commonPool()

snsAsyncClient.publish(publishRequest)
        .thenApply(..)
        .whenComplete(..);

内部代码thenApplywhenComplete将在配置的执行程序上处理SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR


查看完整回答
反对 回复 2023-03-23
  • 1 回答
  • 0 关注
  • 100 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信