?? iothread.java
字號:
package train.server;
import java.net.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: 沈陽化工學院計算機</p>
*
* @author 彭勝勇 胡林
* @version 1.0
*/
public class IOThread extends Thread {
IoStrategy brokerServer;
Socket skt;
int num;
public static int count;
public IOThread(IoStrategy brokerServer) {
this.brokerServer = brokerServer;
num = count++;
}
public void run() {
while (true) {
System.out.println("Thread " + num + " is in waiting stage.");
synchronized (this) {
try {
this.wait();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Thread " + num + " is in service stage.");
this.brokerServer.ioService(skt);
this.skt = null;
}
}
public boolean isIdle() {
return skt == null;
}
public synchronized void setSocket(Socket skt) {
if (this.skt == null) {
this.skt = skt;
this.notify();
}
}
public String toString() {
return "Thread " + num + ":" + skt;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -