2017-10-10 1 views
0

저는 시스템을 만들려고합니다. 요청을 받고, 그것들과 몇 가지 작업을하고 (같은 요청을 그룹화하는 등) 1-2 초 지연으로 응답을 보냅니다.자바 서블릿 비동기 컨텍스트가 다른 요청을 차단합니다.

그래서 AsyncContext을 사용하여 즉시 응답을 보내지 않고 필요할 때 보냅니다.

그러나 내가 을 사용할 때 AsyncContext은 첫 번째 응답이 완료되지 않은 동안 다음 응답을 차단합니다. 테스트를 위해 한 번에 3 건의 아약스 요청을 보냅니다..

3 개의 완료되지 않은 요청을 처리하는 대신 내 코드는 1 차 요청이 완료 될 때까지 기다린 다음 2 차가 작동하고 3 차가 2 차가 완료 될 때까지 기다립니다. 그것이 로그에

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 

    System.out.println("GET " + new Date().toString()); 

    if(!request.getRequestURL().toString().contains("localhost")) { 
     try { 

      AsyncContext context = request.startAsync(); 

      context.start(new Runnable() { 
       @Override 
       public void run() { 

        try { 

         prepare(request, response); 
         addToPool(request, response, context); 

         System.out.println("fin GET " + new Date().toString()); 

        } catch (Exception e) { 
         e.printStackTrace(); 
        } 
       } 
      }); 

     } catch (Exception ex) { 
      ex.printStackTrace(); 
     } 
    } 
} 

은 다음과 같습니다

GET Tue Oct 10 10:16:25 
Try combine: false 
Req added to waitlist 
fin GET Tue Oct 10 10:16:25 
Completed 

GET Tue Oct 10 10:16:30 
Try combine: false 
Req added to waitlist 
fin GET Tue Oct 10 10:16:30 
Completed 

GET Tue Oct 10 10:16:35 
Try combine: false 
Req added to waitlist 
fin GET Tue Oct 10 10:16:35 
Completed 

AsyncContext이처럼 행동 갈까요 아니면 내가 뭔가 잘못하고있는 중이 야?

P. 내가없이 사용 에게 AsyncContext을 시도했다 "context.start (새의 Runnable() {..."그리고 난 같은 결과를 얻을 수

UPDATE -.. JS 코드 나는 버튼을 클릭에 multiReq를 호출하고 이벤트.

function multiReq() { 
    getCurrAcc(); 
    getCurrAcc(); 
    getCurrAcc(); 
} 

function getCurrAcc() { 

    $.ajax({ 
     type: "GET", 
     contentType: 'application/json', 
     url: "http://new59d2023b5d1a4.amocrm.ru.myhost.localarea.local/private/api/v2/json/accounts/current", 
     xhrFields: { 
      withCredentials: true 
     }, 
     success: function (data) { 
      alert(JSON.stringify(data)); 
     }, 
     error: function (request, status, error) { 

      alert(JSON.stringify(request)); 
     } 
    }); 
} 
+0

자바 스크립트의 관련 부분을 표시하십시오 –

+0

** 무서운 웜뱃 **, 완료 – ToNY

답변

0

이 문제는 . 크롬 노점 이전 REQ 응답을 얻기 위해 GET 요청. 그것은 크롬 캐시에 의해 발생 된 것. 자바 코드 또는 에 AsyncContext 아니었다 없음 캐시 옵션 일을 해결하지 문제입니다.

관련 문제