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(..)
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
。
添加回答
举报
0/150
提交
取消