简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM