繁体   English   中英

如何一次并行调用多个REST服务?

[英]How to call the multiple REST services in parallel at a time?

我想从REST客户端调用多个REST服务,如何将它们作为用于每个调用的单个线程来调用。 我想同时打电话给他们

以下是我出于自己的目的针对多个数据库请求的示例代码

   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请求以使其适合您的用途。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM