user1120821
user1120821

Reputation: 449

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

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?

Upvotes: 12

Views: 8048

Answers (1)

Jesse Wilson
Jesse Wilson

Reputation: 40593

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 using Call.enqueue() (asynchronous) the limits are in Dispatcher.

Upvotes: 10

Related Questions