Hi guyz, I need some guidance! i have a java process being initated from a batch file!! but when ever i am closng the terminal on which the batch file is executing the java process also shutsdown!! i need it to run even after i have closed the terminal!!
yup! i ahve .bat and .sh files for the windows and linux environment!
can somebody suggest what could be done if am on the windows environment. Say i close the cmd after executing the batch file and i do not want the java process to exit. My question is.. can i deal with this issue with a piece of code ?
Provided the Java implementation on your platform has the relevant support (it should), you can use a very simple bootstrap static main method to load your program as a new (daemon) process in the OS. Look at java.lang.Process and java.lang.Runtime, and try running "java ..." as the execution command. The new process runs asynchronously in a new JVM, so closing the current JVM down (by exiting the bootstrap class) is no problem. Also, the new process isn't tied to the current screen, so it will continue to run even after you log off.
I've used this successfully on both Windows and Unix without changing the code between platforms: however, you may want to provide the execution syntax "java ..." as part of the bootstrap method's arguments from your batch file, so the program itself is devoid of OS dependency (e.g. location of installed JRE).
You'll probably also want to code someway to shutdown the service (from within the running process) and this is often done using an appropriate signal via sockets.
Alternatively, if you don't care about a neat shutdown, you should be able to kill the process at any time (using "kill" on Unix or the Task Manager on Windows).
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / AmazonAmazon UK )