幕布斯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(..)
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
提交
取消