1、Executor接口
public interface Executor{
voidexecute(Runnsable command);
}
2、使用该接口的web server
class TaskExecutionWebServer{
private static final int NTHREADS=100;
private static final Executorexec=Executors.newFixedThreadPool(NTHREADS);
public static voidmain(Strings[] args) throws IOException{
ServerSocket socket=new ServerSocket(80);
while (true){
final Socket connecton=socket.accept();
Runnable task=new Runnable(){
public void run(){
handleRequest(connection);
}
};
exec.execute(task);
}
}
}
public class ThreadPerTaskExecutor implementsExecutor{
public void execute(Runnalbe r){
new Thread(r).start();
};
}