Hi John,
So as far as server app code dealing with a forced shutdown, may I ask what
you recommend for situations where there's some task running that really
should be allowed to complete? For example, would you have the concept of an
internal registry, where tasks are registered, and a shutdown signal means
"no new tasks allowed, and wait for running tasks to finish"?
Thanks for any further insights on this!
Aaron
"John D. Mitchell" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
On Thu, Mar 6, 2008 at 11:28 AM, Aaron Crow <[EMAIL PROTECTED]>
wrote:
Is it ok to shut down a Restlet server using Unix kill?
Depends on your application's specifics.
For example, the oldest Restlet-based production code that I have is
an authentication gateway that I would just kill outright.
What does Restlet do in this case?
Unless something has been changed in the v1.1+ world, nothing. The
JRE receives the signal and dies and the Restlet infrastructure
doesn't do anything about it.
And does anyone have any good advice on what the application
code might do to handle this event properly?
You can register a shutdown hook:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)
BUT! Be clear that your shutdown hook thread may or may not ever get
invoked -- it depends on things like which signal is being sent.
So, it's best to presume that your Java application may be killed at
anytime. I.e., make sure that your code deals appropriately with the
error conditions that that may cause in some reasonable way given your
application's semantics.
That said, I like to add an "admin" resource to my RESTful apps so
that I can check their state, sometimes tweak settings on the fly, and
ask them to gracefully shutdown. Then I use that ability in my init
scripts. For what it's worth, I like adding this more general
capability to my systems instead of just using something like the
Tanuki wrapper stuff -- for all of the added flexibility and isn't
platform specific.
Hope this helps,
John