OkHttp, how to set the maximum connection pool size (not the maximum idle connections)

In OkHttp, I cannot find a way to set a hard maximum connection pool size. From the documentation https://square.imtqy.com/okhttp/3.x/okhttp/okhttp3/ConnectionPool.html it is clear that you can set maximum idle connections, but not a common maximum. This means that under high load it can exceed any limits.

Is there a way to maximize the pool? If not, why not?

+4
source share
1 answer

Connections are either active, or held by a specific call in flight, or are in standby mode and in the pool. Limit the total number of connections by limiting the number of threads that make HTTP calls. If you use Call.execute()(synchronously), just proportionally distribute your thread pool. If you use Call.enqueue()(asynchronous), the limits are at Dispatcher.

+3
source

Source: https://habr.com/ru/post/1685632/


All Articles