Nallarc
Nallarc

Reputation: 31

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

I want to call multiple REST services from the REST client how can I call them as single thread used for each call. I wan to call them in parallel

Upvotes: 2

Views: 3870

Answers (1)

Md Ayub Ali Sarker
Md Ayub Ali Sarker

Reputation: 11547

The below is the sample code for multiple database request that i made for my purpose

   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()

what you need to changes it to make http request to make able for your porpose.

Upvotes: 3

Related Questions