• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

join()

 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ..
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic