Meaningless Drivel is fun!*
The moose likes Threads and Synchronization and the fly likes join() and start() order making the differnce Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "join() and start() order making the differnce" Watch "join() and start() order making the differnce" New topic
Author

join() and start() order making the differnce

Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Hi savvy pals,

Why does the following two codes making a difference.






Why second code is not behaving like the first ??? Cannot we join first and then start.

Thanks !!!

SCJP 6.0 96%

(Connecting the Dots ....)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

You can only meaningfully call join() on a thread that has already been started. join() waits for the thread to finish, and then returns. Calling it before a thread even starts is obviously not going to work. If it did work -- i.e., if it didn't return until the thread was finished -- then you'd never get to the next statement to call start(), right? So the thread would never run at all.

[Jess in Action][AskingGoodQuestions]
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Thanks ernest !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: join() and start() order making the differnce