Prevent Jetty’s singleton shutdown thread from breaking restarts

By default, Jetty uses a singleton shutdown thread, registered as a
shutdown hook, to stop its components. This single thread breaks the
restart logic in devtools as a second restart causes a second attempt to
start the singleton shutdown thread which fails with an
IllegalStateException. This processing is unnecessary in a Spring Boot
application as the application context’s lifecycle when ensure that
Jetty is shutdown.

This commit updates the embedded Jetty container to remove its
components from Jetty’s shutdown thread. This leaves the thread with
no components to manage at which point it removes its registration as a
shutdown hook.

Closes gh-3343
This commit is contained in:
Andy Wilkinson 2015-06-29 16:52:05 +01:00
parent a09a29be44
commit cc3aea2b69
2 changed files with 6 additions and 1 deletions

View File

@ -16,8 +16,10 @@
package org.springframework.boot.autoconfigure.websocket;
import org.eclipse.jetty.util.thread.ShutdownThread;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
@ -38,7 +40,9 @@ public class JettyWebSocketContainerCustomizer extends
@Override
public void configure(WebAppContext context) throws Exception {
WebSocketServerContainerInitializer.configureContext(context);
ServerContainer serverContainer = WebSocketServerContainerInitializer
.configureContext(context);
ShutdownThread.deregister(serverContainer);
}
});

View File

@ -81,6 +81,7 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer {
// Start the server so that the ServletContext is available
this.server.start();
this.server.setStopAtShutdown(false);
}
catch (Exception ex) {
// Ensure process isn't left running