[英]Java: How URLConnection treats completed TCP connection?
When I use URLConnection to do some HTTP requests, I could only close InputStream and OutputStream, but not the socket. 当我使用URLConnection来做一些HTTP请求时,我只能关闭InputStream和OutputStream,而不能关闭套接字。
Does the class automatically close the socket? 该类是否自动关闭套接字? How does it do it?
它是如何做到的? Will the server return a FIN or something else?
服务器会返回FIN还是其他什么?
If I produce many threads including each URLConnection in them, will it automatically reuse the socket? 如果我生成许多线程,包括其中的每个URLConnection,它会自动重用套接字吗? I caught some packages, it shows about every 3 connections share 1 socket.
我抓了一些包,它显示了每3个连接共享1个套接字。
It pools the socket for possible future reuse within a short period of time, I think 5 or 15 seconds. 它将插槽集中在一起,以便将来在短时间内重用,我想5或15秒。 HttpURLConnection.disconnect() is the only thing that actually closes it.
HttpURLConnection.disconnect()是唯一实际关闭它的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.