我有以下 Spring MVC 3.2 代码(它使用DeferredResult 类):
@RequestMapping(value = "getMessages", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public DeferredResult<List<Message>> getMessages(@RequestParam final Long senderId) {
final Long recipientId = memberService.retrieveCurrentMember().getId();
final String messageRequestKey = new StringBuilder().append(senderId).append(":").append(recipientId).toString();
final DeferredResult<List<Message>> deferredResult = new DeferredResult<List<Message>>(null, Collections.emptyList());
messageRequests.put(messageRequestKey, deferredResult);
deferredResult.onCompletion(new Runnable() {
@Override
public void run() {
messageRequests.remove(messageRequestKey);
}
});
List<Message> unReadMessages = messageService.findUnreadMessages(senderId, recipientId);
if (!unReadMessages.isEmpty()) {
deferredResult.setResult(unReadMessages);
}
return deferredResult;
}
此方法由 ajax 调用连续轮询,它系统地导致 Tomcat 在第 9 次方法调用时崩溃。请注意,Tomcat 崩溃时没有任何错误消息。
如果有人可以帮助我确定此代码表现出这种行为的原因,我将非常感激,或许可以通过给我有关如何调试应用程序/tomcat 的提示。