Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
快速提问:
如果 Socket 对象(及其本地缓存的 InputStream 和 OutputStream 对象)超出范围并被垃圾回收,连接是否在 JVM 中保持打开状态?(即,不会在监听服务器上抛出 EOFException)
不,终结器(与套接字相关的某些对象)最终将关闭套接字......至少在任何理智的实现中,IMO,就像任何其他非内存资源(文件句柄等)一样。不过,这将在垃圾收集器的时间一时兴起 - 我会有效地将其视为编程错误。