Harish Narayana wrote:When do we use Join in Multithreading
Suppose There is a two thread A and B. and if you started both thread by A.start(), and B.Start(). After that you see that both thread start and work according to the thread scheduler. But during this run if you want that B thread will complete their execution before A thread then write code B.join(). This method join the thread B to to the execution pool of thread A and complete their execution first. and after that A will run.
We use join() whenever we need to attach a thread at the end of another thread.
For eg. Suppose there are two threads : t1 and current thread(main thread) and we invoke start method on t1 and write t1.join();
This will join the current thread(main thread) at the end of thread t1.
As soon as this statement is executed main thread waits for thread t1 to finish.