This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

join, a Thread question

 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

am i implementing this code right?
my output doesnt take effect of join() usage at all.
"Lucy" would come out before Fred does!
 
Henry Wong
author
Marshal
Pie
Posts: 20902
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
am i implementing this code right?
my output doesnt take effect of join() usage at all.
"Lucy" would come out before Fred does!


join() causes the calling thread to wait until the completion of the thread represented by the Thread object. In your example, it will cause the main thread (the thread executing the main method) to wait for the completion of thread two. Thread one runs independently of the other two threads (main and two).

Henry
 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to write code if we want therad two to complete first before thread one ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic