Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

join()

 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone explain to me what exactly does join() do? I am confused about the API documentation's comment. Can anyone please elaborate?
Thanks.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Cameron Park:
Can someone explain to me what exactly does join() do?

Say, you have a thread a which spawns another thread b to do some work (perform a calculation, load an image, or whatever). This thread has been coded to do its job and then terminate.
Sometime later a needs to do something which relies on b having completed its work. That is where you have thread a execute b.join(). The effect of this statement is that a waits for b to complete.
- Peter
 
cameron weirs
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In brief in thread a if u spawned a thread b and want that thread a should not terminate untill thread b (as u might be expecting some output from thread b to be used in a) u have to call b.join() in a ,,this join() will not return untill the thread on which it is called is terminated ..
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey there Cameron Park! i tried a few simple things on join and hope they're as useful to you as they are to me...
here's what i did:
i created 3 Threads namely a, b and c in the main method...
i called a.start() then b.start() then b.join() and finally c.start()...
and here's the result:
a.start()
a registers itself to the Thread scheduler...
then a runs...
b.start()
b registers itself to the Thread scheduler...
then b runs...
main method calls b.join()
application waits for Thread b to return before calling c.start() while Thread a is unaffected by the call...
hope i was able to explain it to you clearly...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic