I got a Queue
in my Server
class:
public class Server{
Queue<Input> inputQueue;
public void start() {
inThread = new InThread(inputQueue);
outThread = new OutThread(inputQueue);
inThread.start();
outThread.start();
}
}
The inThread
will responsible for fill in data in the inputQueue, and the outThread
will responsible for take out data from the outputQueue. InThread
and OutThread
will execute concurrently. Will there a chance that the data will not thread safe? If so, I did some study, it have synchronized variable and synchronized method. Which one should I use? Thanks.