Search code examples
javajoinmultithreadingscjp

Understanding join()


Suppose a thread A is running. I have another thread, B, who's not. B has been started, is on runnable state.

What happens if I call: B.join()?

Will it suspend the execution of A or will it wait for A's run() method to complete?


Solution

  • join() will make the currently executing thread to wait for the the thread it is called on to die.

    So - If A is running, and you call B.join(), A will stop executing until B ends/dies.