public void run() {
while (!stop.get()) {
Socket socket = null;
try {
socket = serverSocket.accept();
socket.setTcpNoDelay(true);
if (!stop.get()) {
// the server service is responsible
// for closing the socket.
try {
lock.lock();
serverService.service(socket);
} finally {
lock.unlock();
}
}
// Sockets are consumed in other threads
// and should never be closed here
// It's up to the consumer of the socket
// to close it.
} catch (SocketTimeoutException e) {
// we don't really care
// log.debug("Socket timed-out",e);
} catch (SocketException e) {
if (!stop.get()){
log.error("Socket error", e);
}
} catch (Throwable e) {
log.error("Unexpected error", e);
}
}
try {
serverSocket.close();
} catch (IOException ioException) {
log.debug("Error cleaning up socked", ioException);
}
}
|