1

I'm working on implementing concurrent third-party API calls for items in a list using CompletableFuture in Java. Instead of processing these requests sequentially, I want them to be executed asynchronously without waiting for each other.

We plan to use CompletableFuture, but I believe we'll need to manage the thread pool carefully. Without setting parameters like max pool size, the application might consume excessive memory and potentially freeze during high traffic.

My main concerns are:

  1. How should we determine appropriate thread pool and queue sizes for this scenario?
  2. We currently have a connection pool (size: 20) for third-party API calls. Should the thread pool size be limited to not exceed this connection pool size?

I'm specifically looking for:

  • Best practices for sizing thread pools and queues in this scenario
  • How to coordinate thread pool size with existing connection pool limitations
  • Potential risks and mitigation strategies for memory management

Can anyone provide guidance on these aspects of concurrent API call implementation using CompletableFuture?

3
  • 1
    If you have a thread pool, why do you need a connection pool? Each thread could just hold one connection, or are more requesting threads per connection useful? Commented Feb 4 at 15:22
  • By “connection pool” do you mean database connections? Commented Feb 4 at 20:57
  • I give an information about only one API structure of our application in my question. It has a list object and it sends a request to the same third-party API for each item in the list and we are planning to organize it with CompletableFuture asynch implementation and threadpool. However, we have other API's in our application and they can send requests to the same API of the third-party, so we try to manage requests to this API of the third-party by connection pool. Do you think there is a problem in this case? Commented Feb 5 at 9:21

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.