import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
Socket accept = serverSocket.accept();
// First stop listening to the port
serverSocket.close();
+ final Thread stopThread = Thread.currentThread();
+
+ // Start a thread that kills the JVM if
+ // server.stop() doesn't have any effect
+ Thread interruptThread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(5000);
+ if (!server.isStopped()) {
+ System.out
+ .println("Jetty still running. Closing JVM.");
+ dumpThreadStacks();
+ System.exit(-1);
+ }
+ } catch (InterruptedException e) {
+ // Interrupted if server.stop() was
+ // successful
+ }
+ }
+ };
+ interruptThread.setDaemon(true);
+ interruptThread.start();
+
// Then stop the jetty server
server.stop();
+
+ interruptThread.interrupt();
+
// Send a byte to tell the other process that it can
// start jetty
OutputStream outputStream = accept
}
+ private static void dumpThreadStacks() {
+ for (Entry<Thread, StackTraceElement[]> entry : Thread
+ .getAllStackTraces().entrySet()) {
+ Thread thread = entry.getKey();
+ StackTraceElement[] stackTraceElements = entry.getValue();
+
+ System.out.println(thread.getName() + " - " + thread.getState());
+ for (StackTraceElement stackTraceElement : stackTraceElements) {
+ System.out.println(" at " + stackTraceElement.toString());
+ }
+ System.out.println();
+ }
+
+ }
+
}