iothread.java~2~
来自「一个可以实现联网售票的火车售票管理系统」· JAVA~2~ 代码 · 共 57 行
JAVA~2~
57 行
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 + =
减小字号Ctrl + -
显示快捷键?