From: Chris H. <ch...@ha...> - 2003-10-22 15:45:51
|
I think your problem is that Jetty kills all its Listener threads during shutdown, and you are using one of those threads to do that shutdown - you are instructing it to commit suicide. You need to activate the shutdown using a thread that is not a child of one of Jetty's ThreadPools. I would try something like this....: public class MortalServer extends org.mortbay.http.Server{ private static String assassinFlag = ""; private Runnable assassin = new Runnable(){ public void run(){ synchronized(assassinFlag){ assassinFlag.wait(); System.exit(); } }}; public void start(){ Thread t = new Thread( assassin ); t.setDaemon(true); t.start(); super.start(); /// Normal Jetty Server start }//-------------- public static void kill(){ synchronized(assassinFlag ){ assassinFlag.notifyAll(); } }//-------------- }//================ Now start Jetty with new MortalServer().start(); and to make the whole JVM stop call MortalServer.kill(); which can be called from within a Jetty webApp using a Jetty Listener thread. HTH Chris ----- Original Message ----- From: "Greg Billock" <gbi...@is...> To: <jet...@li...> Sent: Tuesday, October 21, 2003 10:24 PM Subject: [jetty-discuss] Embedded Jetty having shutdown hook problems > Thanks all for a fantastic embedded JSP/servlet engine. Jetty > is a real treat to work with. > > The application I'm working on uses a Runtime shutdown hook to > shut down various embedded modules, one of which is a module > which wraps a Jetty server, which we run embedded. It is working > very well, with the following hiccup: > > When I run the application stand-alone, i.e. from the command > line, and hit Ctrl-C to shut it down, everything works fine -- > my shutdown hook activates and calls the shutdown lifecycle > method on all my modules, including Jetty (which invokes Server.stop). > > The puzzle is when I invoke System.exit from a thread launched > by Jetty as part of a web application. The JDK docs say that this > will initialize the shutdown hook, which it does, but my shutdown > thread seems to terminate somewhere in the Server.stop method > when I use this mechanism. > > As a workaround, I tried another method where I unregister my > shutdown hook and run a new thread which does the same job, and > then just wait for all the non-daemon threads to terminate. Oddly > enough, the same thing happens: my modules shut down until it > gets to the Jetty module, at which point the thread dies. This > is true whether we call Server.stop or Server.stop(graceful=true). > > I've checked and the thread isn't a daemon thread, and I've > looked through the Jetty code trying to find a smoking gun there, > but found nothing suspicious. I suspect an odd interplay with > a JVM irregularity and something Jetty is doing subsequent to > Server.stop which exercises that irregularity. Any ideas? > > The workaround we're using for now: don't call Server.stop and > allow the daemon threads inside Jetty to terminate abruptly. > This seems to work out OK for us, but I'm not sure it is a good > answer, especially if we were to depend on other Jetty-provided > resource management or anything. > > -Greg Billock > > > > ------------------------------------------------------- > This SF.net email is sponsored by OSDN developer relations > Here's your chance to show off your extensive product knowledge > We want to know what you know. Tell us and you have a chance to win $100 > http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54 > _______________________________________________ > jetty-discuss mailing list > jet...@li... > https://lists.sourceforge.net/lists/listinfo/jetty-discuss > > |