猿问

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

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(..);


幕布斯6054654
浏览 101回答 1
1回答

www说

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(..);内部代码thenApply,whenComplete将在配置的执行程序上处理SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR。
随时随地看视频慕课网APP

相关分类

Java
我要回答