iothread.java~1~
来自「一个可以实现联网售票的火车售票管理系统」· JAVA~1~ 代码 · 共 58 行
JAVA~1~
58 行
package mvc.server;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import java.net.*;
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 + -
显示快捷键?