Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Join method

 
Ruchika Kapoor
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
join() is required when one thread T1 must do its job before thread T2 can complete its work.
So in a way we want the threads to work sequentially, one after another. But this can also be done by putting the logic in two different methods and calling them sequentially. Then what is the use of join() ?

Thanks,
 
Norm Radder
Ranch Hand
Posts: 894
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why couldn't the two threads work in parallel? With savings in elapsed time if the underlying system actually allowed parallel processing. There would be no savings in elapsed time if the jobs are done sequentially.
 
Henry Wong
author
Marshal
Pie
Posts: 21127
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Norm. Just because the join() method is used, doesn't mean that the operation is sequential -- it could be a parallel operation, that has to meetup at a point, before it can continue the next phase.

Henry
 
ranjeev singh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simple example can be - thread T1 does some complex computation and the result is used by thread T2. Unless T1 has completed its job, T2 can not use the computed value. Here T2 can wait for T1 to die. In this scenario use T1.join(). Hope this clarifies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic