[Mulgara-general] Exception on startup

Life is hard, and then you die ronald at innovation.ch
Mon Apr 28 21:31:52 UTC 2008


On Mon, Apr 28, 2008 at 02:52:32PM -0400, Alex Hall wrote:
> Paul Gearon wrote:
> > On Apr 25, 2008, at 4:55 AM, Life is hard, and then you die wrote:
> > 
> >> I think the point Alex is trying to make is that mulgara never shuts
> >> down cleanly, because A) there's no JVM shutdown hook registered
> >> (Runtime.addShutdownHook()), and B) the EmbeddedMulgaraServer just
> >> does a System.exit() without calling stop() on the server. I've
> >> noticed this too: now that we've switched to RMI, none of our
> >> resolvers ever get closed (before our servlet-wrapper called
> >> SesionFactory.close() to clean up).
> >>
> >> I.e. mulgara always "crashes".
> > 
> > I see what you mean.
> > 
> > This is odd, as it USED to be done. Someone has removed it.  I did  
> > notice that the shutdown output had changed, though I didn't realize  
> > why.

Yes, the code and comments in EmbeddedMulgaraServer are a bit odd:

        // Remove the need for shutdownhook
        // force exit when shutdown port is triggered 
        // Runtime.getRuntime().addShutdownHook(server);

Anybody have cvs access to the old code to see why the
addShutdownHook() was commented out? The only potential negative of
that call that I'm aware of is that if you truly embed this in another
app then you want either make the call optional or you want a close()
or something to be able to remove the shutdown-hook again (to release
the root classloader's reference to your class and classloader so your
classes can be reloaded, e.g. in a webapp), but I don't think that
applies here as folks embedding Mulgara are unlikely to try to use
EmbeddedMulgaraServer directly.

> > Strangely, hitting ^C can often take a long time. I had always put  
> > this down to the system flushing buffers. Does the GC cleanup get run  
> > in the case of a break?

No.

> Most of my understanding of this aspect of the system comes from the 
> Javadocs for the java.lang.Runtime class, which I would recommend 
> skimming through.  Apparently, both ^C and System.exit() initiate the 
> same JVM shutdown sequence, which does the following:
> 
> 1.  Starts all shutdown hooks registered via the 
> Runtime.addShutdownHook() method and allows them to run concurrently 
> until the finish.
> 
> 2.  If finalization-on-exit is enabled, then run all uninvoked 
> finalizers.  This option is disabled by default, and I can't find 
> anywhere that we are explicitly enabling it.  Furthermore, this option 
> has been deprecated as it is "inherently unsafe".

Correct.

> So, if we're concerned about the server needing to release resources or 
> flush buffers on shutdown, I would recommend adding a shutdown hook to 
> perform the cleanup.  This would cover both invoking Mulgara with -x, or 
> hitting ^C in the console -- in other words, all user-initiated shutdowns.

Agreed. I.e. just uncomment that addShutdownHook() above.


  Cheers,

  Ronald




More information about the Mulgara-general mailing list