In Java when does a URL connection close?

后端 未结 2 1509
耶瑟儿~
耶瑟儿~ 2020-12-08 17:51

When does java let go of a connections to a URL? I don\'t see a close() method on either URL or URLConnection so does it free up the connection as soon as the request finish

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 18:32

    If you cast to an HttpURLConnection, there is a disconnect() method. If the connection is idle, it will probably disconnect immediately. No guarantees.

提交回复
热议问题