OkHttp how to set maximum connection pool size (no

2019-06-18 02:26发布

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?

1条回答
老娘就宠你
2楼-- · 2019-06-18 02:51

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.

查看更多
登录 后发表回答