listening socket in a new thread
I have min-chat and that is part of client code:
The reason why i have wrote particular thread is that program needs to listen servers socket and perform actions without delays in client code.
final ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
final ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
// Создаем поток для чтения с клавиатуры.
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
Thread t = new Thread(
public void run()
line = in.readUTF(); // In this part socket input data can be delayed and it can be not printed to console immediately
So, why should i make Object streams final ?
PS Feel free to offer another way to communicate with server data to print it to console immediately
Re: listening socket in a new thread
Because the thread will make a thread local copy of the reference and it NEEDS to make sure that those definitions WILL NOT CHANGE.