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:
- How should we determine appropriate thread pool and queue sizes for this scenario?
- 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?