?? cleandeadconnect.java
字號(hào):
public class CleanDeadConnect extends Thread
{ //刪除已死亡的連接的線程
//聲明ServerThread對(duì)象
ServerThread serverThread;
//聲明ClientThread對(duì)象
ClientThread clietThread;
String str;
public CleanDeadConnect(ServerThread serverThread)
{
this.serverThread=serverThread;
}
public void run()
{
while(true)
{
try //線程休眠300毫秒
{
Thread.sleep(10000);
}
catch(InterruptedException E){}
//同步化serverThread.clients
synchronized(serverThread.clients)
{
for(int i=0;i<serverThread.clients.size();i++)
{
//獲取存儲(chǔ)的與客戶端的連接
clietThread = (ClientThread) serverThread.clients.elementAt(i);
if(!clietThread.isAlive())
{
//計(jì)數(shù)器減1
ClientThread.ConnectNumber--;
//從Vector數(shù)組中刪除指定的與客戶端的連接
serverThread.clients.removeElementAt(i);
}
}
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -