posted 12 years ago
I want to shutdown server elegantly. In the code, serverSocket.accept() will be listening at the endpoint forever.
Approach 1, servletSocket.close() will case serverSocket.accept() to throw exception. Ugly, since my isGoingToShutdown flag is completely useless.
Approach 2, use "new Socket(serverSocket.getInetAddress(), serverSocket.getLocalPort()).close();" to interrupt serverSocket.accept(). Works. But why, why it works, and why should I do it in this way?
OK, so that other guy knows Java better than I do, but I bet he can't speak Wuhanese(a Chinese Dialect) like me.