Server.java
public synchronized static void logout(String str) throws IOException{
Enumeration e = v1.elements();
while(e.hasMoreElements()){
Serverthread stm = (Serverthread)e.nextElement();
stm.send(str);
}
Enumeration ex=names.elements();
int indexOf = 0;
while(ex.hasMoreElements()){
String name=(String)ex.nextElement();
String org = str.substring(1);
if(name.equals(org)){
indexOf= names.indexOf(name);
names.removeElementAt(indexOf);
System.out.println("names"+names.size());
break;
}
}
// Serverthread st=(Serverthread)v1.get(indexOf);
Serverthread st=(Serverthread)v1.remove(indexOf);
st.close();
System.out.println(v1.size());
System.out.println("connection closed..");
}
答案 0 :(得分:0)
通常,执行此操作的方法是关闭Thread正在等待的InputStream。如果Thread没有等待任何事情,那么停止它的唯一方法是调用Thread.interrupt()并希望你的Thread检查它是否被中断