开发者

Java: How URLConnection treats completed TCP connection?

开发者 https://www.devze.com 2023-02-13 21:37 出处:网络
When I use URLConnection to do some HTTP requests, I could only close 开发者_如何学GoInputStream and OutputStream, but not the socket.

When I use URLConnection to do some HTTP requests, I could only close 开发者_如何学GoInputStream and OutputStream, but not the socket.

Does the class automatically close the socket? How does it do it? Will the server return a FIN or something else?

If I produce many threads including each URLConnection in them, will it automatically reuse the socket? I caught some packages, it shows about every 3 connections share 1 socket.


It pools the socket for possible future reuse within a short period of time, I think 5 or 15 seconds. HttpURLConnection.disconnect() is the only thing that actually closes it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号