Java 8's java.util.stream.IntStream has a forEach method that allows iterations of a for loop to be executed in parallel. I have implemented it in a Java callout and tested it. Seems to be working fine. The code looks like this:
IntStream.range(0, length).parallel().forEach(i->{
//Code here
});
The above code would execute iterations in parallel. I am seeing a good improvement in the response time with this code. I need the improved response time as I am querying an Active Directory server for groups and doing it sequentially takes about 5-6 seconds. With the above code, it only takes a couple of seconds.
What I wanted to check is the performance implications of using this. In this case, there could be a maximum of 300-350 iterations of the loop and the API is a less frequently used one. Considering that there could be multiple threads involved in executing the above, is there a likelihood of performance implications?