我有一个嵌入式Jetty 6.1.26实例.我希望通过发送的HTTP GET将其关闭/shutdown.所以我创建了一个JettyShutdownServlet:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setStatus(202, "Shutting down.");
resp.setContentType("text/plain");
ServletOutputStream os = resp.getOutputStream();
os.println("Shutting down.");
os.close();
resp.flushBuffer();
// Stop the server.
try {
log.info("Shutting down the server...");
server.stop();
} catch (Exception ex) {
log.error("Error when stopping Jetty server: "+ex.getMessage(), ex);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我发送请求时,Jetty不会停止 - 一个线程一直挂org.mortbay.thread.QueuedThreadPool在线上this.wait():
// We are idle
// wait for a dispatched job
synchronized (this)
{
if (_job==null)
this.wait(getMaxIdleTimeMs());
job=_job;
_job=null;
} …Run Code Online (Sandbox Code Playgroud)