I have a jar that runs forever (infinite loop with socket listening thread) and need it to run in the background at all times. An example would be: "java -jar test.jar" How do I do this? Thanks in advance!
&at the back. However, using this, the program will still be terminated if you closed the terminal that started the program.
screensession, and start the program inside it; you can detach the
screensession and close the terminal. Later on, you can attach to the session again and found yourself back on the console as if you've been there all along. However, you will need to start a screen session before running the program, and if you forgot to do that, you can't do anything about it.
disownjob control from your shell. This will detach the task from your tty and your program won't be terminated when the tty is closed. However, I don't think there's any way to reattach a disowned job.
If by "at all times", you mean it gets started when the machine boots, you'll need to start it as part of the boot-time scripts. The dirty way to do this is to add
java -jar test.jar >/dev/null 2>&1 &
to /etc/rc.local (or replace /dev/null with your favorite log file).
Better would be to make an init.d script that gets started at the appropriate runlevels (you might not want it on runlevel 0, 1 or 6, for instance). That way, you can also have it be restarted automatically if it dies and have a nicer interface to temporarily stopping it.
Small examples at http://www.howtoforge.com/forums/archive/index.php/t-3628.html
Big explanation at http://developer.novell.com/wiki/index.php/Writing_Init_Scripts
You could use the community version of the Java Service Wrapper available from here:
You can then have it start at reboot: