📄 iothread.java~2~
字号:
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 no;
public static int count;
public IOThread(IoStrategy brokerServer) {
this.brokerServer = brokerServer;
no = count++;
}
public void run() {
while (true) {
System.out.println("Thread " + no + " is in waiting stage.");
synchronized (this) {
try {
this.wait();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("Thread " + no + " 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 " + no + ":" + skt;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -