如何停止正在侦听客户端的服务器套接字。我的代码如下所示
private ServerSocket serverSocket;
class ServerThread implements Runnable {
private BufferedReader input;
public void run() {
Socket socket = null;
try {
serverSocket = new ServerSocket(SERVE_LISTEN_RPORT);
} catch (IOException e) {
e.printStackTrace();
}
while (!Thread.currentThread().isInterrupted()) {
try {
socket = serverSocket.accept();
try {
this.input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}
try {
String read = input.readLine();
//Do something
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
try {
serverSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
当我从另一个线程收到命令时,我需要停止这个线程。我已经提出了这个问题,但不知道如何实施。