public class ServerRunnable implements Runnable {
@Override
public void run() {
while (true) {
try {
System.out.println("Waiting...");
Socket sock = socket.accept();
System.out.println("Waiting... 2");
ObjectInputStream stream = new ObjectInputStream(sock.getInputStream());
Object object = stream.readObject();
System.out.println("Waiting... 3");
if (object instanceof Client) {
Client c = (Client) object;
conns.put(c, sock);
System.out.println("Waiting... 4");
ObjectOutputStream oos = new ObjectOutputStream(sock.getOutputStream());
oos.flush();
System.out.println("Waiting... 5");
output.put(sock, oos);
sendMessage(new Message("[" + c.getClientType() + "] " + c.getName() + " connected."));
System.out.println("Waiting... 6");
threads.put(c, new Thread(new ClientHandler(sock, c)));
threads.get(c).start();
System.out.println("Waiting... 7");
updateClientList();
System.out.println("Waiting... 8");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
代码停在" Waiting ... 6" ..出于某种原因,当我启动新线程时,当前线程就停止了。我尝试过几种不同但却无法解决的问题 - 我认为这样做很简单,我做错了。
我做错了什么?