title: Asynchronous servlet not acting asynchronously
body: <p>I have a servlet that takes a request and writes a long response. The response is in a loop that uses Thread.sleep(1000) to simulate a long running operation. I am trying to setup an asynchronous request here, as shown in code. But it is not working. When i invoke several requests to the servlet, they all execute consecutively, not at the same time. What am i doing wrong?</p>
  
  <p>And i though servlets are supposed to be threaded - each request to server causes the container to execute a new thread (or reuse one from the pool).</p>
  
  <pre><code>package test;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import javax.servlet.ServletException;
  
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import javax.servlet.AsyncContext;
  
  import javax.servlet.annotation.WebServlet;
  
  @WebServlet(urlPatterns={"/test"}, asyncSupported=true)
  public class TestServ extends HttpServlet {
  
      @Override
      public void doGet(HttpServletRequest rq, HttpServletResponse rs){
  
          rs.setContentType("text/plain");
          rs.setHeader("Access-Control-Allow-Origin", "*");
  
  
          AsyncContext asy = rq.startAsync(rq, rs);
          asy.start(new Client(asy));
      }
  
  
      @Override
      public String getServletInfo() {
          return "Short description";
      }
  }
  
  class Client implements Runnable {
  
      private int counter = 0;
      private AsyncContext asy;
  
      Client(AsyncContext asy) {
          this.asy = asy;
      }
  
      @Override
      public void run() {
          //run long task here
          try {
              PrintWriter out = asy.getResponse().getWriter();
              while (counter &lt; 5) {
  
                  out.println(counter++ + 1);
                  Thread.sleep(1000);
  
              }
  
          } catch (Exception ex) {
  
          } finally{
              asy.complete();
          }
      }
  }
  </code></pre>