Java Process waitFor() Method

The waitFor() method of Process class is used to wait the currently executing thread until the process executed by the Process object has been completed. The method returns immediately when the subprocess has been terminated and if the subprocess is not terminated, the thread will be blocked.

Syntax

Parameter

NA

Return

This method generally returns the exit value of the process and subprocesses. By default, normal termination is represented by 0.

Example 1

Output:

Ms Paint will run.
You have exited from Ms paint.

Example 2

Output:

Ms Paint will run.
You have exited from Ms-paint.
Notepad will run.
You have exited from Notepad.

Example 3

Output:

Both Ms paint and Notepad will run simultaneously.

1. Ms Paint will run.
2. Notepad will run.

You have exited from Ms-paint.
You have exited from Notepad.

Next TopicJava-timer