Java Language Process Blocking vs. Non-Blocking Calls

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

In general when making a call to the command line, the program will send the command and then continue its execution.

However you may want to wait for the called program to finish before continuing your own execution (ex. The called program will write data to a file and your program needs that to access that data.)

This can easily be done by calling the waitFor() method from the returned Process instance.

Usage example:

//code setting up the commands omitted for brevity...

ProcessBuilder pb = new ProcessBuilder(cmds);

try {
    Process p = pb.start();
    p.waitFor();
} catch (IOException e) {
    e.printStackTrack();
} catch (InterruptedException e) {
    e.printStackTrace();
}

//more lines of code here...


Got any Java Language Question?