This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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!


boolean b = true;<br />System.out.println ("I believe in Java.<br />Java will make my dream come " + b);
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18498
    
  40

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 ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: join, a Thread question
 
Similar Threads
Unexpected result with Threads join() method...
Threads Again
Thread.sleep() guaranteed behaviour
Is Kathy Sierra right when she said "Each thread will start, and each thread will run to completion"
Threads