检查 Java HTTP 连接池
HttpUrlConnection 默认使用持久连接 (http://download.oracle.com/javase/6/docs/technotes/guides/net/http-keepalive.html)。 有没有办法检查Java HTTP连接池?例如检查池中有多少个打开的连接?
HttpUrlConnection uses persistent connections by default (http://download.oracle.com/javase/6/docs/technotes/guides/net/http-keepalive.html).
Is there any way to inspect Java HTTP connection pool? Eg check how many open connections in the pool?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是没有。在 Oracle 的 VM 中,理论上您可以使用反射检查
sun.net.www.http.HttpClient.kac
中的静态缓存。这是一个Map
,其值是缓存的HttpClient
实例的Stack
。然而,缓存还包含已经关闭或超时的连接,并且在不实际执行真正的 HTTP 请求的情况下过滤掉这些连接似乎不是一个合理且简单的方法,在这种情况下,废弃的连接将自动重新连接。Unfortunately no. In Oracle's VM, you can in theory inspect the static cache in
sun.net.www.http.HttpClient.kac
using reflection. This is aMap
, which values areStack
s of cachedHttpClient
instances. The cache however also contains already closed or timed out connections and it does not seem to be a reasonable easy way to filter these out, without actually performing a real HTTP request, in which case abandoned connections will automatically reconnect.