title: Asynchronous Servlet with Embedded Jetty
body: <p>I want to build a real simple example for invoking a asynchronous servlet in an embedded Jetty server. When I try to start a Runnable from the AsyncContext of the Request, I get a NullPointerException.
  This is the server code:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
      Server server = new Server(8080);
      ServletHandler handler = new ServletHandler();
      server.setHandler(handler);
      ServletHolder holder = handler.addServletWithMapping(AsyncServlet.class, "/*");
      holder.setAsyncSupported(true);
      server.start();
      server.join();
  }
  </code></pre>
  
  <p>This is the servlet code:</p>
  
  <pre><code>public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
      final AsyncContext ctxt = req.startAsync();
      ctxt.start(() -&gt; {
          ctxt.complete();
      });
  }
  </code></pre>
  
  <p>And this is the error with stack trace:</p>
  
  <pre><code>java.lang.NullPointerException
  at org.eclipse.jetty.server.AsyncContextState$2.run(AsyncContextState.java:168)
  at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620)
  at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540)
  at java.lang.Thread.run(Thread.java:745) 
  </code></pre>
  
  <p>Maybe the server needs any additional configuration. Any suggestions?</p>
  
  <p>Addition: The same servlet runs without any change in an embedded tomcat.</p>