Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

join()

 
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
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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...
 
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
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic