orm initialization as a daemon // this involves in closing file descriptors, recording PIDs, etc. d. {@linkplain #init() init}(); } else { // if you are already daemonized, no point in daemonizing yourself again, // so do this only when you aren't daemonizing. if(you decide to launch a copy into background) { d.daemonize(...); System.exit(0); } } // your normal main code follows // this part can be executed in two ways // 1) the user runs your process in the foreground // 2) you decided to daemonize yourself, in which case the newly forked daemon will execute this code, // while the originally executed foreground Java process exits before it gets here. ... }
Alternatively, your main class can extend from Daemon, so that you can customize some of the behaviors.
@author Kohsuke Kawaguchi