package name.ixr.webserver; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * WEB JOB * @author IXR */ public class TaskJob implements Runnable{ @Override public void run() { try { //创建线程池 ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*Global.pool); //监听 ServerSocket serverSocket = new ServerSocket(Global.port); System.out.println(String.format("Post:%s/tWebRoot:%s", Global.port,Global.directory.toURI().toString().replace("file:/", ""))); System.out.println("WebServer Run Succeed"); while(true){ Socket socket = serverSocket.accept(); executorService.execute(new ProcessRunnable(socket)); } } catch (IOException e) { System.out.println(String.format("Post:%s/tBe Taken", Global.port)); } } }