简体   繁体   中英

Does SocketChannel.close() close the socket also?

I have a server program that needs to close any connections that remain when the server is shutting down. I know I need to call SocketChannel.close() . My question is if I also need to close the Socket associated with the SocketChannel or if SocketChannel.close() does that automatically.

Of course it closes the socket. What else would it be for? The only exception is when the channel is registered with a Selector, when the actual close is deferred to the next select operation.

SocketChannel.close() should close the Socket. However, there have been some bugs around this issue (should have been solved a long time ago). http://bugs.sun.com/view_bug.do?bug_id=4960962 . Another situation that can cause problems: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6179351

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