Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

join()

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit and Salil.....Salil your code cleared everything
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic