Java: Daemonize Your Application
By admin on Feb 3, 2009 in Java, open source
Akuma is a Java library you can use in your application to support Unix daemonization. By taking advantages of POSIX API, this library lets you fork your process into background with proper daemonization steps.
One feature of this library lets you fork a copy into background as a real Unix daemon, when started in the foreground. While doing this, you can also tweak JVM parameters or arguments.
Another feature of this library lets you re-launch a JVM with different VM options, without forking a new child process. This allows applications to tweak parameters that can be only changed at the JVM start-up time, such as heap size, diagnostic options, etc.
This overwrites the current process via POSIX exec call, so you’ll retain the same stdin/stdout/stderr, and the same parent process. In comparison, Starting yourself with Runtime.exec will create a child process with different stdin/stdout, and when the parent is killed, the child is left behind without a controlling terminal.
This library also lets you write a multi-process network server that listens on the same TCP/IP port. By forking multiple processes, you improve the robustness of your server — a single destroyed process will not interrupt the service as other worker processes will take over the processing.
This is how Unix daemons have been traditionally written, such as Apache, yet it was impossible to do this in Java because it doesn’t provide an API to let file descriptors to be inherited into children.
Sorry, comments for this entry are closed at this time.