1 while (true) { // 等待用户请求 2 request = rServer.accept(); // 接收客户机连接请求 3 receiveThread = new serverThread(request); // 生成serverThread的实例 4 receiveThread.start();// 启动serverThread线程 5 } 6 7 while (true) { 8 Socket clientSocket=null; 9 try { 10 // 接收客户连接,只要客户进行了连接,就会触发accept();从而建立连接 11 clientSocket = serverSocket.accept(); 12 executorService.execute(new SocketHandler(clientSocket)); 13 } catch (Exception e) { 14 logger.error(StringHandler.GetException(e)); 15 e.printStackTrace(); 16 } 17 }