How to use Servlet 3 @WebServlet & async with Spring MVC 3?

Ben picture Ben · Jul 27, 2010 · Viewed 12.2k times · Source

I would like to integrate the servlet 3.0 async support with spring MVC. Something like:

@RequestMapping("/chat")
@WebServlet(name="myServlet", asyncSupported=true)
public String getMessage(String userName) {
      ......
}

is it possible?

Answer

Krish Bheeman picture Krish Bheeman · Oct 29, 2010

Not so fast, it is not that easy to implement good long polling. The method you mentioned works well, but there is a serious issue of "thread starvation"

Each Long polling will use up one thread, if you have 1000 concurrent user you would need 1000 thread to service the long polling request ( which most of the time does update of the server side status on the client browser)

Jetty 6 has a continue pattern whcih cleverly releases the thread of long polling request to be used by rhe real application logic.