我想要实现的是客户端关闭的时候,给服务器发送一条退出消息,然后由run()解析执行后,引用stop()方法,由stop()来关闭该客户端的线程。public void run() {
Object clientMsg = in.readObject();
if (clientMsg instanceof Message) {
switch (((Message) clientMsg).msgType) {
case LOGOUT:
stop();
break;
........
}public void stop() {
try {
listener.interrupt();
listener = null;
handlers.removeElement(this);
out.close();
socket.close();
} catch (Exception e) {
}
}不做任何判断,然后关闭这个线程,可是似乎还是没有关闭掉?CPU的使用率一直是100%
请问该如何解决呢?又或者是别的原因引起的?
Object clientMsg = in.readObject();
if (clientMsg instanceof Message) {
switch (((Message) clientMsg).msgType) {
case LOGOUT:
stop();
break;
........
}public void stop() {
try {
listener.interrupt();
listener = null;
handlers.removeElement(this);
out.close();
socket.close();
} catch (Exception e) {
}
}不做任何判断,然后关闭这个线程,可是似乎还是没有关闭掉?CPU的使用率一直是100%
请问该如何解决呢?又或者是别的原因引起的?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货