wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes join() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "join()" Watch "join()" New topic
Author

join()

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531


output that comes it hard to understand.....

i am trying to understand the join() method in which i want the 3rd thread and 2nd thread to join the first thread.....can anyone explain me this?

thanks
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

i want the 3rd thread and 2nd thread to join the first thread.

Right now your main thread will wait for the 1st thread to join i.e. the run method completes.

If you want the 3rd and 2nd thread to join the 1st thread, then you'll have to call join on t2 and t3 in the 1st thread not in the main method. You need to understand the use of join method properly. When you call join on an instance of a Thread class, the method call returns i.e. the method call ends when the thread on which the join method was called ends i.e. the run method completes. So if in thread A1 you call join on thread A2, then A1 will continue execution when A2 thread completes...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Salil Vverma
Ranch Hand

Joined: Sep 06, 2009
Posts: 253

i want the 3rd thread and 2nd thread to join the first thread.


Joining the second and third thread means the first thread would start its execution only then the joining threads would have completed the execution. I have tweaked your code a bit for the same.

Kindly have a look and let me know whether it fulfills your need.



Regards
Salil Verma
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
Thanks Ankit and Salil.....Salil your code cleared everything
 
Don't get me started about those stupid light bulbs.
 
subject: join()
 
Similar Threads
How to make one thread die before another thread
Explain Join() method of Thread
join() method in Thread doesn't work as expected
Thread
join method