(二)——Dispatcher

 1 package my.tomcat2;
 2 
 3 import java.io.IOException;
 4 import java.net.Socket;
 5 
 6 /**
 7  * 分发器,用于创建线程,使得多个客户端可以同时连接服务器
 8  */
 9 public class Dispatcher implements Runnable {
10     private Socket client;
11     private Request request;
12     private Response response;
13     
14     public Dispatcher(Socket client) {
15         this.client = client;
16         request = new Request(client);
17         response = new Response(client);
18     }
19 
20     @Override
21     public void run() {
22 //        new Servlet(client).service();
23         try {
24             WebApp.getServlet(request.getUrl()).service(request, response);
25         } catch (ClassNotFoundException e) {
26             e.printStackTrace();
27         } catch (IllegalAccessException e) {
28             e.printStackTrace();
29         } catch (InstantiationException e) {
30             e.printStackTrace();
31         }
32     }
33 }
原文地址:https://www.cnblogs.com/AI-Cobe/p/9606771.html