서브렛 다중 스레드 테스트

3540 단어 javaEE
  • 서브렛은 실행할 때 하나의 실례만 있지만 서비스 방법은 다중 루트
  • doGet을 다시 쓰는 방법으로 테스트
    	/**
    	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		System.out.println(new Date()+":  get  ------");
    		System.out.println("     :"+this+";hashCode:"+this.hashCode());
    		System.out.println("    :"+Thread.currentThread());
    		
    	}
  • 테스트 출력 결과
    Sun Jan 14 19:31:28 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-4,5,main]
    Sun Jan 14 19:31:29 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-5,5,main]
    Sun Jan 14 19:31:29 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-6,5,main]
    Sun Jan 14 19:31:29 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-7,5,main]
    Sun Jan 14 19:31:30 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-9,5,main]
    Sun Jan 14 19:31:30 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-8,5,main]
    Sun Jan 14 19:31:30 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-10,5,main]
    Sun Jan 14 19:31:30 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-1,5,main]
    Sun Jan 14 19:31:30 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-2,5,main]
    Sun Jan 14 19:31:31 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-3,5,main]
    Sun Jan 14 19:31:31 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-4,5,main]
    Sun Jan 14 19:31:31 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-5,5,main]
    Sun Jan 14 19:31:31 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-6,5,main]
    Sun Jan 14 19:31:31 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-7,5,main]
    Sun Jan 14 19:31:31 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-9,5,main]
    Sun Jan 14 19:31:32 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-8,5,main]
    Sun Jan 14 19:31:32 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-10,5,main]
    Sun Jan 14 19:31:32 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-1,5,main]
    Sun Jan 14 19:31:32 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-2,5,main]
    Sun Jan 14 19:31:32 CST 2018:  get  ------
         :com.oracle.first.login@31f35411;hashCode:838030353
        :Thread[http-nio-8080-exec-3,5,main]
  • 상기 테스트에서 알 수 있듯이 서브렛의 실례는 하나입니다. 서비스 방법은 다중 루트입니다. 현재 루트가 점용될 때 용기는 새로운 루트를 호출하여 처리 요청을 진행합니다
  • tomcat8은 순환 분배 라인의 알고리즘을 사용하여 서비스 방법을 호출한다
  • 좋은 웹페이지 즐겨찾기