Within my java application, I have a log backup function:
rt = Runtime.getRuntime();
pr = rt.exec(command);
int exitVal = pr.waitFor();
if(exitVal == 0)
return true
The problem is it takes a while to backup the logs and to get a response, until then my application freezes. If I remove the pr.waitFor()
function call, I get a response, but the log backup fails to work.
waitFor() method causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits.
So you can create another thread which do execution of command. pr = rt.exec(command); . You might have to perform this task asynchronously. Because until subprocess get terminated process will wait for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With