我正在使用 CometProcessor 在 Tomcat 7.0 上实现长轮询。困扰我的是除了 CometEvent.EventType.BEGIN 之外我没有收到任何其他事件。代码示例:
@Override
public void event(CometEvent event) throws IOException, ServletException {
HttpServletRequest request = event.getHttpServletRequest();
HttpServletResponse response = event.getHttpServletResponse();
if (event.getEventType() == CometEvent.EventType.BEGIN) {
LOGGER.info("Begin for session: " + request.getSession(true).getId());
} else if (event.getEventType() == CometEvent.EventType.ERROR) {
LOGGER.error("Error for session: " + request.getSession(true).getId());
event.close();
} else if (event.getEventType() == CometEvent.EventType.END) {
LOGGER.info("End for session: " + request.getSession(true).getId());
event.close();
} else if (event.getEventType() == CometEvent.EventType.READ) {
LOGGER.info("Read from session: " + request.getSession(true).getId());
}
我认为它可能会导致内存泄漏,因为在 BEGIN 事件中我将响应对象存储在本地数组中。
有没有人有任何想法可能是错的?