I am executing another java program through a Process object.
This takes some time to complete. In the mean time, will the parent program continue running or will it be on hold, to wait for the child process to stop?
I know that two threads can run in parallel, can a thread be used to execute this other program?
Please let me know if you need any more details, if this became too abstract.
It will execute separately unless you either block waiting for data from the other process (e.g. calling Process.getInputStream()
and then reading from it), or call Process.waitFor()
. The second process has its own threads - these are not the threads of the process that happens to start the second process.
Of course, it's possible that both processes will end up dealing with the same resource and have to cooperate in that sense - but in general, using multiple processes is a separation level up from threads. (It's relatively tricky to get processes to access the same memory, to get their threads to coordinate with each other, etc.)
See more on this question at Stackoverflow