如果我不使用自定义连接管理器,我还应该在Apache HttpClient上设置ConnectionRequestTimeout吗? [英] Should I still set ConnectionRequestTimeout on Apache HttpClient if I don't use a custom connection manager?
问题描述
我正在使用 Apache RequestConfig 在我的 HttpClient
上配置一些超时。
I am using Apache RequestConfig to configure some timeouts on my HttpClient
.
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(timeout)
.setSocketTimeout(timeout)
.setConnectionRequestTimeout(timeout) // Can I leave this out..
.build();
CloseableHttpClient httpClient = HttpClients.custom()
//.setConnectionManager(connectionManager) // ..if I don't use this
.setDefaultRequestConfig(config)
.build();
调用 setConnectionRequestTimeout(timeout)是否合理
即使我没有自定义连接管理器/池设置?
Does it make any sense to call setConnectionRequestTimeout(timeout)
even I don't have a custom Connection Manager / Pool set up?
据我了解, setConnectionRequestTimeout(timeout)
用于设置等待连接的时间连接管理器/池。
As far as I understand, setConnectionRequestTimeout(timeout)
is used to set the time to wait for a connection from the connection manager/pool.
请注意,我没有在 httpClient
上设置连接管理器(请参阅注释行)。
Note that I am not setting a Connection Manager on the httpClient
(see commented line).
推荐答案
connectionRequestTimeout
当你有一个连接池并且它们是所有人都忙,不允许连接管理器给你一个连接来发出请求。
connectionRequestTimeout
happens when you have a pool of connections and they are all busy, not allowing the connection manager to give you a connection to make the request.
那么,问题的答案是:
即使我没有设置自定义连接管理器/池,调用setConnectionRequestTimeout(超时)
也没有任何意义吗?
Does it make any sense to call setConnectionRequestTimeout(timeout) even I don't have a custom Connection Manager / Pool set up?
是YES。
这是因为默认实现有一个内部连接池。
所以,是的,指定连接请求超时是有意义的。实际上这是一个安全的好方法。
This is because the default implementation has an internal connection pool. So, yes it makes sense to specify a connection request timeout. Actually it is a good, safe practice.
这篇关于如果我不使用自定义连接管理器,我还应该在Apache HttpClient上设置ConnectionRequestTimeout吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!