I'm beginner in java programming, I wrote basic server which is in endless loop and starts new Threads
as shown below.
while (true) {
DatagramPacket receivePacket = new DatagramPacket(receive, receive.length);
socket.receive(receivePacket);
username = new String(data(receive));
Thread t = new Thread() {
@Override
public void run() {
try {
clientHandler(receivePacket);
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
};
t.start();
threads.add(t);
t.setName(username);
}
Now my goal is to call method to getThreadList
when I type anything in my console window. I've tried Scanner
and System.in.read()
but they stop whole loop, waiting for my input. Is there any solution to this?