0

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

1 回答 1

0

AWS 开发工具包异步请求返回CompletableFuture. 默认情况下,在返回的实例上调用thenApply(..)和将在诸如. 异步配置的思想是提供线程池执行器,用于后续对like和的调用。这个执行器不会被应用到方法和由于实现的原因(如果执行器没有被传入,它将被默认使用,或者我们可以将自定义执行器作为第二个方法参数传递)。whenComplete(..)CompletableFuturesdk-async-response-0-XSdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTORCompletableFuturethenApply(..)whenComplete(..)thenApplyAsyncwhenCompleteAsyncCompletableFuturethenApplyAsync(..)ForkJoinPool.commonPool()

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

里面的代码thenApplywhenComplete并将在配置的执行程序上处理SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR

于 2019-07-13T19:33:26.637 回答