개발일기

0309_ InvokeHandler Method , Thread Pool 이란?

포로리33 2023. 3. 20. 17:04
  • InvokeHandler Method

       InvokeHandler Method를 알기 위해서는 먼저 MVC패턴의 구조를 알아야 한다.

       MVC패턴에서 DispatcherServlet 은

       들어온 요청을 Controller에게 작업을 위임하고 Controller가 끝낸 결과물을 리턴받아 

       View 오브젝트에 Model로 넘겨주어 진행한다.

       이때, 어떤 Controller를 찾아 작업을 수행해야할지 찾아주는 객체를 HandlerMapping이라고 한다.

        이 Handler Mapping 과정에서 구현체인 RequestMappingHandlerAdapter 클래스가

        invokeHandlerMethod를 호출하는 것이고, 여기서 Handler를 찾아 실행한다.

       결국 invokeHandlerMethod란 들어온 요청을 처리하는 Handler를 찾아 호출하여 처리하는 핵심메서드인 것이다.

  • Thread Pool

       서버가 모든 요청에 대해 Thread를 생성하게 되면 성능 저하 등의 문제가 발생한다.

       따라서 미리 Thread를 만들어 놓고, 만들어진 Thread 내에서 이를 재사용하는 것을 Thread Pool 이라고 한다.                   

ThreadPoolExecutor( int corePoolSize, int maximumPoolSize,
 		   long keepAliveTime, TimeUnit unit, Blocking Queue<Runnable> workQueue)

                                                                                                                                                                                                          corePoolSize : 실행할 최소 Thread 수

        maximumPoolSize : 최대 Thread 수 

        long keepAliveTime : Thread 미사용시 제거 대기시간

        TimeUnit unit : keepAliveTime의 시간 단위

        BlockingQueue<Runnable> workQueue : 요청된 작업들이 저장될 Queue