I have a usecase where I have to call one method 13 times. This method is in turn making 2 api calls and since we cannot change the structure of this method , therefore calling that method as it is. For individual method call , it is taking 11-12 sec. While executing these 13 method calls sequentially, it is giving result in 2.3 min(approx).I am trying to making parallel calls, using executerService in java, to this method, but getting output in 1.8 – 2.0 minutes. Which is not expected. I want the output within 20 sec.(as we are already able to get individual call’s output in 11 sec).
There are multiple ways of implementing parallel calls in java. But my current useCase best fits with using executerService,So I am trying to get the desired result by using executerService only.
I have used it in two different ways:
- By creating a list of callable tasks and then using .invokeAll() to create futures
- By using .submit() for each method call to create futures
and then using .get() to get the output result from these futures.
Both the above mentioned way are not giving output with efficient latency. Their latency is somewhat equal to the latency of sequential execution of these method call.
Note : The flow of executing tasks doesn’t matter in my usecase.