• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

join()

 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit and Salil.....Salil your code cleared everything
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic