线程"块"或者"停止"在我的代码中的某一点 - 网络/服务器

时间:2017-03-10 13:55:31

标签: java multithreading networking

    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" ..出于某种原因,当我启动新线程时,当前线程就停止了。我尝试过几种不同但却无法解决的问题 - 我认为这样做很简单,我做错了。

我做错了什么?

0 个答案:

没有答案