Queue我在Server班上得了一个:
public class Server{
Queue<Input> inputQueue;
public void start() {
inThread = new InThread(inputQueue);
outThread = new OutThread(inputQueue);
inThread.start();
outThread.start();
}
}
inThreadwill负责在inputQueue中填写数据,willoutThread负责从outputQueue中取出数据。InThread并将OutThread同时执行。数据是否有可能不是线程安全的?如果是这样,我做了一些研究,它有同步变量和同步方法。我应该使用哪一个?谢谢。