What is Thread.Join() in threading?
There are 2 versions of Thread.Join :-
- Thread.join().
- Thread.join(Integer) this returns a Boolean value.
The Thread.Join method is very useful for determining if the thread has completed before starting another task. The Join process waits a specified amount of time for a thread to end. If the thread ends before the time-out, the Join givess true; otherwise it gives False. Once you call Join, the calling procedure stops and waits for the thread to signal that it is done. For Example you have the "Thread1" and "Thread2" and while executing 'Thread1" you call "Thread2.Join()".So the "Thread1" will wait until "Thread2" has completed its execution and again invoke "Thread1". Thread.Join(Integer) ensures that threads do not wait for a long time. If it exceeds a specific time which is provided in integer the waiting thread will start.