In OkHttp I cannot find a way to set a hard maximum connection pool size. From the documentation https://square.github.io/okhttp/3.x/okhttp/okhttp3/ConnectionPool.html it is clear that you can set a maximum idle connections, but not an overall max. That means that with high load it can grow beyond any limit.
Is there a way to maximize the pool? If not, why not?
Connections are either active and held by a particular in-flight call, or idle and in the pool. Limit the total number of connections by limiting the number of threads executing HTTP calls. If you’re using
Call.execute()
(synchronous) just size your thread pool appropriately. If you’re usingCall.enqueue()
(asynchronous) the limits are inDispatcher
.