top of page

Thread.join() method in java

What basically happen in normal thread flow in java is , let's suppose when main the is running and one another thread t1 is running , in this time whenever main thread work is completed then it terminated the main thread it will not wait another thread t1 to complete.


Using Join method me can make the parent thread to wait for child thread


let's understand this using sample code

How java works in normal flow without using join() method



Output

Here we can see that even after main thread terminates still thread t1 is working


When we use join the thread t1 to main thread



Output:


Main thread started

running task on thread t1

Main thread finished work


Here we can see main thread is waiting for thread t1 to complete the task.


Thanks for Reading.

Happy Coding 🚀

 
 
 

Comentarios


Call 

7869617359

Email 

Follow

  • Facebook
  • Twitter
  • LinkedIn
  • Instagram
Never Miss a Post. Subscribe Now!

Thanks for submitting!

bottom of page