title: Programmatic Jetty shutdown
body: <p>How to programmatically shutdown embedded jetty server?</p>
  
  <p>I start jetty server like this: </p>
  
  <pre><code>Server server = new Server(8090);
  ...
  server.start();
  server.join();
  </code></pre>
  
  <p>Now, I want to shut it down from a request, such as <a href="http://127.0.0.1:8090/shutdown" rel="noreferrer">http://127.0.0.1:8090/shutdown</a>
  How do I do it cleanly? </p>
  
  <p>The commonly proposed solution is to create a thread and call server.stop() from this thread.
  But I possibly need a call to Thread.sleep() to ensure that the servlet has finished processing the shutdown request.</p>