서블릿 필터에서 filterChain.doFilter (request, response); 체인에서 다음 요청을 전달해야합니다. 그러나 고려 다음 두 코드 :
코드 1 :서블릿 필터가 모호하게 작동합니까?
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException
{
filterChain.doFilter(request, response);
try
{
Thread.sleep(20000);
}
catch(Exception e)
{
}
}
코드 2 :
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException
{
try
{
Thread.sleep(20000);
}
catch(Exception e)
{
}
filterChain.doFilter(request, response);
}
두 필터가 동일하게 실행합니다. 즉, 둘 다 요청을 처리하기 전에 20 초가 걸립니다.
실제로 실제로 일어날 일은 Code1
이 즉시 처리되어야하고 Code2
이 20 초 후에 처리되어야합니다. 왜 필터에서이 모호성이 있습니까?
응답과 연결된 출력 스트림 (또는 작성자)을 명시 적으로 닫음으로써 클라이언트를 릴리스 할 수는 있지만이를 보장 할 수는 없습니다. –