📄 connectionwatcher.java
字号:
class ConnectionWatcher extends Thread {
protected chatserver server;
protected ServerWriter writer;
public ConnectionWatcher(chatserver s, ServerWriter writer) { // constructor
super(s.CurrentConnections,"ConnectionWatcher");
server = s;
this.writer = writer;
this.start();
}
public synchronized void run() {
while(true) {
try { this.wait(10000); }
catch (InterruptedException e) {
System.out.println("Caught an Interrupted Exception");
}
synchronized (server.connections) {
for (int i = 0; i < server.connections.size(); i++) {
Connection c;
c = (Connection) server.connections.elementAt(i);
if (!c.isAlive()) {
server.connections.removeElementAt(i);
writer.outdata.push(server.connection_list.getItem(i) +
" has left chat!\n");
synchronized(writer) {writer.notify();}
server.connection_list.remove(i);
i = i - 1;
}
} // end of for
} // end of synchronized
} // end of while
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -