开发者

Are the http requests to a HttpServlet handled asynchronously

I've been told that the java servlets may run asynchronously. But does that mean that the requests to a single servlet are handled asynchronously, or that only the requests to different servlets are asynchronous.

Basically, I have this one servlet in my project:

public class DummyServlet extends HttpServlet
{
...
protected void doGet(HttpServletRequest request, HttpServletResponse response) 
{
    response.setContentType("text/plain; charset=utf-8");

    PrintWriter writer = new PrintWriter(response.getOutputStream());

    writer.wri开发者_如何学Pythonte("DummyServlet invocation");

    System.out.print("Invocation: " + counter);

        Thread.sleep(5000);

    System.out.println(" ... done.");
    counter++;

    writer.flush();
    writer.close();
}

Now, when I make two simultaneous requests, the second waits for the first to end. How can one achieve asynchronous behavior in this scenario?

UPDATE: The requests are handled asynchronously, just my requests weren't generated asynchronously.


By implementation every servlet request runs in a different thread. So it is an asynchronous behaivour.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜