2016-09-21 3 views
-1

RESTクライアントから複数のRESTサービスを呼び出すにはどうすればよいですか 私はそれらを呼び出しごとに1つのスレッドとして呼びます。私は以下の並列一度に複数のRESTサービスを並列に呼び出すにはどうすればいいですか?

+0

'' 'java.util.concurrent.Future'''はあなたの友だちです –

+0

[どのトピックが許可されている](http://stackoverflow.com/help/on-topic)と[良い質問](http://stackoverflow.com/help/how-to-ask)ガイド。現在書かれているように、SOの話題です。 – dubes

+0

ありがとうございました。この洞察を伝えるためのPawel – Nallarc

答えて

1

でそれらを呼び出すために私は私の目的のために作られた複数のデータベース要求のためのサンプルコードされたワン

CompletableFuture<Company> companyCompletableFuture = CompletableFuture.supplyAsync(() -> { 
      return Company.find.where().eq("id", id).findUnique(); 
     }); 

     CompletableFuture<List<Domain>> domainsCompletableFuture = CompletableFuture.supplyAsync(() -> { 
      return Domain.find.where().eq("company_id", id).findList(); 
     }); 

     // wait for all the data 
     CompletableFuture allDoneFuture = CompletableFuture.allOf(companyCompletableFuture, domainsCompletableFuture); 

allDoneFuture.get(); // wait for all done 
company = companyCompletableFuture.get(); 
domain = domainsCompletableFuture.get() 

あなたはそれがhttpリクエストは、あなたのporposeのためにできるようにするために作るための変更に必要なもの。

+0

コードで詳細情報を伝えてくれてありがとう、ありがとう – Nallarc

関連する問題