Does the main thread in java finish up before any processes it might create using Runtime class finish executing
java, multithreading, runtime.exec
Solution
You might want to check out the java.lang.Process class. You probably want something like this:
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();
The subprocess may be receiving a SIGHUP and exiting.
EDIT:
In context, something like this, I would think:
try
{
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();
}
catch(IOException e)
{
//add logging functionality
e.printStackTrace();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
Problem
I am using the Runtime class to execute a piece of installation of a software. However, its not working, meaning that, after I fire the job (which is created using the Runtime class), after sometime (which is very soon) the installation job just exits. I think the problem is that the main thread must be finishing up and thus killing the Process that is created using the Runtime class. Am I correct ? And what is the solution here ? this is how I fire my job inside teh main class : ``` try { Runtime.getRuntime().exec(cmd); } catch(IOException e) { //add logging functionality e.printStackTrace(); } ``` Soon after this command, the main function finishes. There is no problem with the Runtime command. It works .. I can even see it starting(the installation taht I am firing thru the code) and then it suddenly exits.