[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Using org.apache.service to create Java Daemons



* Aaron Brashears <aaron@lns.com> [010118 22:27]:
> I'm researching writing a daemon in Java. Surprisingly, there seems to
> be very little documentation around the net for doing this.

Aaron, most of what makes daemons special is they automatically detach
from their controlling terminal, setup init as their parent, and some
other fun things (as outlined in Stevens' APUE).

If you are writing the thing in Java, isn't part of what you are after
is keeping from having to do this sort of stuff? :)

As I can see it, there are three approaches one could take. First, write
a small C wrapper to do the setup work as described in Stevens that runs
the java virtual machine with your code. Small, easy, and locates the
platform dependent code in one place, though it does require writing
some C.

The second approach is to use a POSIX compatibility library -- I saw one
only two months ago, a quick trip through google should find it in a
hurry. Then, your java code *may* be able to do most of the things
Stevens outlines.

The third approach is to try to get the tomcat code working for your
code. This might not be so easy, though you at least have some assurance
that someone else managed to get it to work too, with tomcat. :)

If it were my program, after the initial setup, I would have my code
wrapped in something such as:
for (;;) {
	// fun stuff
}
and start it all with the C wrapper.

HTH :)

-- 
``Oh Lord; Ooh you are so big; So absolutely huge; Gosh we're all
really impressed down here, I can tell you.''



Reply to: