Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

join() and start() order making the differnce

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ernest !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic