What is the use of join() method in Thread class?
join() method is used to club two threads into a single thread.
if you call join() method on a thread, then the current thread will be paused until the other thread is finished.
if you call join() method on a thread, then you are sending a request to other thread to get paused until current thread is finished.
none of the above
Assume that two threads are running thread-A and thread-B, where CPU is executing those two threads with time slicing mechanism. Now if thread-A calls join() method on thread-B's object then thread-A will be suspended until CPU finishes thread-B's work. Once CPU finishes thread-B work, then it will resume thread-A and continue to run it.
So here "join" says join CPU with me after executing other thread, until then suspend.
Note: There is one more version of join() method which says for how many milli seconds you want to keep your thread in suspended state.
Back To Top