私の要件は、私はRESTアプリケーションで複数のAPIを呼び出す必要があります。私は、それぞれのAPIが別のAPIからの応答を待っているかどうかにかかわらず、独立して動作するようにしたい。つまり私は、以下のようにあなたが別のスレッド内API
電話をかけることができますつのAPIリクエストが5秒を取るならば、すべてのAPIリクエストも同時に複数のApiリクエストをspring mvcで呼び出します
0
A
答えて
0
を5秒を取るべきである必要があります。
new Thread(new Runnable() {
public void run() {
try {
// Do your api call here
}
catch(Exception e)
{// Log or do watever you need}
}
このようにAPIコールがasynchronously
に動作します!
0
org.springframework.web.client.AsyncRestTemplateクラスを使用すると、ListenableFutureを返して値を非同期的に取得できます。したがって、あなたのメソッドは最も遅いapi呼び出しと同じ時間がかかります。
public static void main(String[] args) {
AsyncRestTemplate asycTemp = new AsyncRestTemplate();
HttpMethod method = HttpMethod.GET;
// create request entity using HttpHeaders
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
HttpEntity<String> requestEntity = new HttpEntity<String>("params", headers);
ListenableFuture<ResponseEntity<String>> future = asycTemp.exchange("https://www.google.com", method, requestEntity, String.class);
ListenableFuture<ResponseEntity<String>> future1 = asycTemp.exchange("https://www.yahoo.com", method, requestEntity, String.class);
ListenableFuture<ResponseEntity<String>> future2 = asycTemp.exchange("https://www.bing.com", method, requestEntity, String.class);
try {
// waits for the result
ResponseEntity<String> entity = future.get();
// prints body source code for the given URL
System.out.println(entity.getBody());
entity = future1.get();
System.out.println(entity.getBody());
entity = future2.get();
System.out.println(entity.getBody());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
関連する問題
- 1. 複数のAPI URLを呼び出して同時に呼び出します
- 2. Spring Javaで同時に複数のWebサービスを呼び出す
- 3. ソケットリスナー複数同時AcceptAsync呼び出し
- 4. Retrofit 2で複数のリクエストを同時に呼び出す方法
- 5. 複数のウェブサイトで同時にAPI呼び出しが行われる
- 6. mvcで複数回呼び出されたAjaxリクエスト
- 7. 複数の呼び出しでテストレストapi
- 8. C++:複数の* .exeを同時に呼び出す
- 9. 複数のAPI呼び出しを同期
- 10. 同じspring mvcコントローラメソッドを定期的に呼び出す方法
- 11. MVCファイルストリーム複数呼び出し
- 12. Spring-Boot:複数のリクエストを同時に処理する
- 13. 複数のajaxが同時に呼び出す
- 14. Java Spring MVCからihomefinderのIDX MLS SOAP APIを呼び出す
- 15. Redux saga複数のAPI呼び出し
- 16. 複数のAPI呼び出しが
- 17. Spring MVCコントローラからの非同期呼び出し
- 18. 複数のAJAXを同じ関数を呼び出して呼び出す
- 19. レスポンスオブジェクトを一貫して更新する複数の同時API呼び出しを取得できません
- 20. PowerShell C#ホスト - 複数の同時リモートコマンド呼び出し
- 21. トルネードでの非同期リクエストでの複数のデータベース呼び出し
- 22. Java Spring MVCからNode.Js Rest API(POST)を呼び出す
- 23. jqueryまたはjavascriptは複数のアクションを同時に呼び出していますが、同時に呼び出すことはありません
- 24. Spring MVCリフレクション - Pojoセッターを呼び出す
- 25. Marketo API - 最大10個の同時API呼び出し
- 26. OAuth2でAPIを呼び出すC#MVC
- 27. 複数のCTEを同じクエリで複数回呼び出す
- 28. Spring Webサービスの同時呼び出しの制限
- 29. 非同期API呼び出しを再帰的に呼び出します。
- 30. Spring-MVC:要求時にコントローラメソッドが呼び出されない