Java HttpURLConnection和pooling
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java HttpURLConnection和pooling,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1682字,纯文字阅读大概需要3分钟。
内容图文
![Java HttpURLConnection和pooling](/upload/InfoBanner/zyjiaocheng/819/b031082a844c460a91139770fb9bf025.jpg)
在阅读了有关Java HttpURLConnection的所有类型的文档后,我仍然感到很困惑,因为它有什么样的集合以及它如何实现连接.
例如,以下代码
URL url = new URL(someUrl);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
OutputStream os = connection.getOutputStream();
InputStream is = connection.getInputStream();
/** Write something to os and flush */
/** Read from is */
os.close();
is.close();
connection.disconnect();
>是否需要刷新并关闭以使底层套接字可重用?
> connection.disconnect()会关闭底层套接字(从而使其无法使用)吗? keep-alive会影响这种行为吗?
>如果我使用不同的URL对象,但使用相同的URL,从它们创建的连接是否会共享底层套接字?当URL的主机部分相同但路径不同时怎么样?
>什么时候汇集连接会被破坏?
>控制池大小的系统属性是什么?
此外,如果您还可以将Android版本与Java进行比较,那就太棒了.
谢谢
解决方法:
- Do both
os
andis
need to be flushed and closed for the underlying socket to be reusable?
关闭输入流就足够了.您无法刷新输入流,并在关闭冗余之前刷新输出流.
- Will
connection.disconnect()
close the underlying socket (and hence make it unreusable)?
它可以作为关闭底层连接的暗示.
Does
keep-alive
affect this behavior?
是.如果不存在,则必须关闭连接.
- If I use different URL objects, but with the same URL, will the
connection
s created from them share the underlying sockets?
是.
How about when the host part of the URL is the same, but paths are different?
是.
- When will pooled connections be destroyed?
空闲超时后.
- What’s the system property that controls the size of the pool?
我不知道有一个,但如果有,它将在网络属性页面中定义,您可以通过Javadoc找到它.
Additionally, if you could also compare the Android version with Java it would be great.
我相信Android根本不会集合,但是当它们切换到OpenJDK源时应该会改变.
内容总结
以上是互联网集市为您收集整理的Java HttpURLConnection和pooling全部内容,希望文章能够帮你解决Java HttpURLConnection和pooling所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。