I have to do a benchmarking for performance difference between multi-threaded and multi-process architecture in java. This is the code i used to create new process
for(int i=0;i<100;i++)
{
try {
Process p = Runtime.getRuntime().exec("java -jar myjar.jar " + input);
} catch (Exception e) {
System.out.println("Exception in creating process");
e.printStackTrace();
}
}
Is there a way to know when all the processes started by my main java program has finished execution?
Yes: call waitFor for each Process:
If p is already finished the method returns inmediatly. If it’s not, it waits.
Edit: if you need to do other things in the mean time, execute this for/wait in another Thread. The thread will end the loop when all process are terminated, and you can do other things: