This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes join, a Thread question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "join, a Thread question" Watch "join, a Thread question" New topic
Author

join, a Thread question

adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186

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
Sheriff

Joined: Sep 28, 2004
Posts: 19935
    
  44

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Satyajeet Kadam
Ranch Hand

Joined: Oct 19, 2006
Posts: 215
How to write code if we want therad two to complete first before thread one ?
 
 
subject: join, a Thread question
 
It's not a secret anymore!