如果我不使用自定义连接管理器,我还应该在 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.
所以,您的问题的答案:
So, The answer to your question of:
调用setConnectionRequestTimeout(timeout)有意义吗即使我没有设置自定义连接管理器/池?
Does it make any sense to call setConnectionRequestTimeout(timeout) even I don't have a custom Connection Manager / Pool set up?
是.
这是因为 默认实现 有一个内部连接池.所以,是的,指定连接请求超时是有意义的.实际上,这是一种很好且安全的做法.
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屋!