2012-10-01 1 views
0


서버 측에서 JMS를 사용하여 알림 시스템을 만들려면 Comet을 시작하십시오.
웹 서비스에서 CometHandler에 알리는 서블릿에 비동기 메시지를 보내야합니다.
각 요청에 새로운 처리기가있는 혜성 화

글래스 피시 (http://docs.oracle.com/cd/E18930_01/html/821-2418/ggrgt.html#ggrgr)의 카운터 샘플을 사용하기 시작했으나 많은 처리기를 생성합니다. .

문제는 (내가 생각하는)이 CometHandler가 클라이언트에 응답을 보낸 다음 그 자체를 다시 시작 핸들러의 onEvent에 혜성 핸들러가

protected void doGet(HttpServletRequest req, HttpServletResponse res) 
      throws ServletException, IOException { 

    CounterHandler handler = new CounterHandler(); 
    handler.attach(res); //here the response of this request is attached to handler 

    CometEngine engine = CometEngine.getEngine(); 
    CometContext context = engine.getCometContext(contextPath); 

    context.addCometHandler(handler); 
} 

그런 다음 각 요청에 생성된다는 점이다

public void onEvent(CometEvent event) throws IOException { 
    if (CometEvent.NOTIFY == event.getType()) { 
     response.getWriter().write("something") //response is the attached one 
     // commented out the resume if it is Http Streaming 
     event.getCometContext().resumeCometHandler(this); 
    } 
} 

그리고 HTML 페이지에서 나는 이처럼 longPoll을 수행하기 위해 JQuery를 사용합니다.

그래서, 각각의 getJSON, 새로운 CometHandler가 생성되고 그 전에는 "잊어 버렸습니다".
질문 :이 작업을 수행하는 더 좋은 방법이 있습니까?
그리고 내가 사용하는 다음이 다른 경우 처리기를 다시 시작해야하는 이유는 무엇입니까?
도움 주셔서 감사합니다.

- 편집 -

나는의 HttpSession 속성에 cometHandler을 넣어하려고 노력하지만, 내가 addCometHandler (핸들러)를 사용해야하기 때문에 자바 독으로 말을하기 때문에 문제가 여전히 남아 :

Add a CometHandler which will starts the process of suspending the underlying response.  
The underlying HttpServletResponse will not get committed until 
CometContext.resumeCometHandler(CometHandler) is invoked, unless the 
CometContext.setExpirationDelay(long) expires. 

은 그리고 각 요청에 대한 새로운 CometHandler을 만들지 할 수있는 방법이 있는지

Resume the Comet request and remove it from the active CometHandler list. Once resumed,  
a CometHandler must never manipulate the HttpServletRequest or HttpServletResponse as 
those object will be recycled and may be re-used to serve another request. If you cache 
them for later reuse by another thread there is a possibility to introduce corrupted 
responses next time a request is made. 


그래서 나도 몰라 resumeCometHandler를 사용하여 다른 일을 (이)를 참조하십시오. 나는 카운터를 넣고 onInitialize 핸들러 메소드에서 증가시키고 onTerminate 핸들러 메소드에서 그것을 감소시키고 각 요청에서 증가시킨다.

답변

0

결국에는 문제가없는 것처럼 보입니다.
각 요청은 핸들러를 작성하지만 목록에서 제거되며 가비지 콜렉터가 호출 될 때 지워집니다.
시도해보십시오. gc를 강제로 실행하고 일시 중지 된 목록에없는 모든 CometHandler가 완료됩니다.
많은 새로운 요청을 강제로 시도하고 가비지 컬렉터가 호출 될 때 혜 택 처리기가 많이 인스턴스화 될 때 호출되므로이 방법이 너무 마음에 들지 않습니다.
모든 새로운 아이디어를 환영합니다.
감사합니다.

관련 문제