server:socket监听端代码package server;import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;public class Server {
private List<Socket> list = new ArrayList<Socket>();
private final static int THREAD_NUM = 3;
private ExecutorService exec = Executors.newFixedThreadPool(THREAD_NUM);
private static  boolean running = false;
private static final int PORT= 10080;
private ServerSocket serverSocket = null;


private void initial(){
System.out.println("server:initial the thread pool with " + THREAD_NUM + " threads");

for (int i = 0; i < THREAD_NUM; i++) {
exec.execute(new Handler(list));
}
}

public boolean isBound(ServerSocket serverSocket){
return (serverSocket != null && serverSocket.isBound());
}

private void bind() {
if(!isBound(serverSocket)){
System.out.println("server:bind to the port " + PORT);
try {
serverSocket = new ServerSocket(PORT);
} catch (IOException e) {
e.printStackTrace();
}
}
}

private void handle(){
synchronized (list) {
try {
Socket socket = serverSocket.accept();
System.out.println("server:accept a new socket");
list.add(socket);
list.notify();
} catch (IOException e) {
e.printStackTrace();

}

}

public void start(){
System.out.println("server:start the server");
running = true;
initial();
while(running){
bind();
handle();
}
}

}
handler:处理接收到的套接字。package server;import java.net.Socket;
import java.util.List;public class Handler implements Runnable {
private static int num = 0;
private List<Socket> list= null;
private static final boolean running = true;

public Handler(List<Socket> list) {
super();
num++;
this.list = list;
System.out.println("Handler:Thread " + num + " is started");
} @Override
public void run() {
while(running){
synchronized (list) {
if(list.isEmpty()){
System.out.println("handler:no task and wait");
try {
list.wait();
} catch (InterruptedException e) {
e.printStackTrace();
} }
else {
System.out.println("handle a task");
list.remove(0);
System.out.println("handler:Thread " + num + " handle completly and notify the other thread");
list.notify();
}
}

}
}}运行服务器端代码package test;import server.Server;public class Test { public static void main(String[] args) {
Server server = new Server();
server.start();
}}
测试连接代码package client;import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;public class Client {

public Client(int count){
for (int i = 0; i < count; i++) {
connect();
}
}
public void connect() {
try {
Socket socket = new Socket("192.168.6.38", 10080); } catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
Client client = new Client(3);
}
}console输出内容:server:start the server
server:initial the thread pool with 3 threads
Handler:Thread 1 is started
Handler:Thread 2 is started
handler:no task and wait
Handler:Thread 3 is started
handler:no task and wait
server:bind to the port 10080
handler:no task and wait
server:accept a new socket
server:accept a new socket
server:accept a new socket
本来想达到,三个线程等待,server端存储socket的list新增监听到的socket之后,唤醒handler,但是失效了。求解