File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 18836
    
  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