Ability to terminate the AbstractBaseService's thread

2 views
Skip to first unread message

shlomo

unread,
Oct 26, 2008, 4:18:51 PM10/26/08
to lifeguard-dev
Hi David,

I'm running a lifeguard Service (extends AbstractBaseService) as a
standalone process, not controlled by the PoolManager. As such, I want
to make sure that the JVM is resilient in the face of rogue
exceptions, OutOfMemoryErrors, and random core dumps - not that I
expect them, I just need to make sure my service will restart itself
if it ever dies.

For this purpose I decided to use the Apache Commons Daemon library.
With this library you can implement a Daemon interface and the "jsvc"
runtime container will control the lifecycle of the java program. As
with all containers, you give up some control over the lifecycle
events of your application, and this is the case with the Daemon
library as well.

I need to allow the Daemon library to cleanly stop the
AbstractBaseService thread - by setting some flag on the
AbstractBaseService or something. I see from the sources that it would
be easy to add such a flag.

Would you be interested in adding this feature to the mainline
lifeguard - the ability to signal the AbstractBaseService to return
from its run() method? I can provide the patch if necessary.

.. Shlomo

David Kavanagh

unread,
Oct 26, 2008, 5:28:24 PM10/26/08
to lifegu...@googlegroups.com
Shlomo,
To keep things robust, I've simply added a "while (true) do .... done"
to my script that runs the service. So, if the JVM dies for any
reason, I re-direct output to a log file, but the endless loop ensures
the service will always be running.
Does the Daemon lib do something more?

David

shlomo....@gmail.com

unread,
Oct 27, 2008, 2:20:39 AM10/27/08
to lifegu...@googlegroups.com
David,

The Apache Commons Daemon library provides a native wrapper that
handles all the boilerplate unix-style daemon things (e.g. a pid-file,
the ability to start/stop/restart), wraps SIGnals, and provides the
java application with early-warning that the process is being shut
down (see http://commons.apache.org/daemon/index.html).

I have two requirements:
- I would like to perform some cleanup in my
"hey-the-jvm-is-shutting-down" handler, and I need to make sure the
Service is no longer processing messages when that happens.
- I want the service to automatically restart itself if it dies for any reason.

The Daemon library provides these features.

In general the ability to notify the Service that it should terminate,
from within the same JVM, might be a useful feature. Let me know if
you're interested in the patch (it's small!).

.. Shlomo

Reply all
Reply to author
Forward
0 new messages