0 Replies - 519 Views - Last Post: 30 November 2017 - 12:16 PM Rate Topic: -----

#1 Criel  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 146
  • Joined: 11-March 11

When running Async method calls, is this needed/overkill?

Posted 30 November 2017 - 12:16 PM

I am creating an API that has multiple REST calls and was looking to async them. I have had experience with CompletableFuture in the past and have used it to run multiple API calls asynchronously but was thinking further for some more improvements but am not sure if it would be useless as the CompleteableFuture creates and processes on it's own thread.

Currently I have 3 separate methods that simply call other APIs and add the response to a mapper.

//request1/2/3 passed in as parameter with multiple values of string in each request

CompletableFuture<Map<String,Response1> response1 = null;
CompletableFuture<Map<String,Response2> response2 = null;
CompletableFuture<Map<String,Response2> response2 = null;

response1 = async.getResponse1(request1)
response2 = async.getResponse2(request2)
response3 = async.getResponse3(request3)
CompletableFuture.allOf(response1,response2,response3).join();


This will fire off asynchronous calls to each of these methods and process them on different threads, but since we are passing a List of strings which we are iterating through in each getResponse1/2/3 method and firing off synchronous calls to the REST services, could it be improved further?

In the async.getResponse1/2/3 methods, is it possible to use a parallel stream to call the REST services asynchronously from the async class? Would it have any affect on performance?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1