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.

有帮助吗?

解决方案 2

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top