我想优雅地关闭serversocket。到目前为止我已经有了这段代码:
@Override
public void init() throws IOException {
listener = new ServerSocket();
listener.setSoTimeout(1);
listener.setReuseAddress(true);
listener.bind(new InetSocketAddress(85));
clientProcessingPool = Executors.newFixedThreadPool(50);
while (!clientProcessingPool.isShutdown()) {
try {
Socket socket = listener.accept();
clientProcessingPool.submit(new StlExecutor(socket, this));
} catch (SocketTimeoutException e) {
} catch (Exception e) {
logger.error("", e);
e.printStackTrace();
}
}
listener.close();
}
public void stop() throws Exception {
clientProcessingPool.shutdownNow();
}
设置如此低的SO_TIMEOUT是否合理?什么是合理的价值呢?什么是性能影响?