OkHttp如何设置最大连接池大小(不是最大空闲连接数) [英] OkHttp how to set maximum connection pool size (not max idle connections)

查看:2237
本文介绍了OkHttp如何设置最大连接池大小(不是最大空闲连接数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OkHttp中,我找不到设置硬最大连接池大小的方法.从文档 https://square.github.io/okhttp/3.x/okhttp/okhttp3/ConnectionPool.html 很明显,您可以设置最大空闲连接数,但不能设置总的最大空闲数.这意味着,在高负载下,它可以增长到任何极限.

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?

推荐答案

连接处于活动状态并通过特定的正在进行中的呼叫保持,或者处于空闲状态并在池中.通过限制执行HTTP调用的线程数来限制连接总数.如果您使用的是Call.execute()(同步),请适当调整线程池的大小.如果您使用的是Call.enqueue()(异步),则限制在Dispatcher中.

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.

这篇关于OkHttp如何设置最大连接池大小(不是最大空闲连接数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆