Tahir Rauf
Tahir Rauf

Reputation: 514

Java8 Parallel HTTP calls

First thing first, this question is for Java8.

Having said that, let's go to the problem in hand.

I am new to java and there seems to be so many different ways to accomplish this. However, I am not sure which one is the correct one. Also, limit of concurrent calls also makes it challenging for me to solve.

Can someone please point me to the Java topic which I need to learn?

Thanks for your time. I really appreciate your help.

Upvotes: 0

Views: 764

Answers (2)

Chayne P. S.
Chayne P. S.

Reputation: 1638

On top of my head

  • Apache HttpClient
  • Spring-Boot @Async, threadPoolTaskExecutor limit to maxPoolSize = 8

That should do it.

Edited If you do not want to use Spring, you can just use ForkJoinPool with Stream. Check this out -> https://www.baeldung.com/java-8-parallel-streams-custom-threadpool

Upvotes: 1

the_tech_maddy
the_tech_maddy

Reputation: 597

IMO, If your project is developed using Spring framework, then I would suggest you to go with WebFlux. It is the implementation of RxJava, a reactive programming approach. The documentation link is here. It includes an HTTP client, which supports non-blocking, called WebClient with which you can make HTTP calls.

Otherwise, CompletableFuture with ExecutorService having customized threadpool configuration depending on your API concurrency. This will be the good option.

Upvotes: 1

Related Questions