📄 serverwriter.java
字号:
import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.*;
import FIFO;
class ServerWriter extends Thread {
protected chatserver server;
public Vector OutputStreams;
public FIFO outdata;
private String outputline;
public ServerWriter(chatserver s) { // constructor
super(s.CurrentConnections, "Server Writer");
server = s;
OutputStreams = new Vector();
outdata = new FIFO();
this.start(); // start this thread
}
public synchronized void run() { // lock this thread to prevent multiple access
while(true) {
try { this.wait();} // wait for wakeup by notify()
catch (InterruptedException e)
{ System.out.println("Caught an Interrupted Exception");}
outputline = outdata.pop(); // get the message from top of FIFO
// lock the Vector to prevent the watcher thread from
// doing something with Vector before this code finishes
synchronized(server.connections) {
for (int i = 0; i < OutputStreams.size(); i++)
{ PrintStream out;
out = (PrintStream) OutputStreams.elementAt(i);
out.println(outputline);
}
} // end of synchronized
} // end of while
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -