• Post Reply Bookmark Topic Watch Topic
  • New Topic

working of join()

 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the basic work of join() , i am very much confused in that.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, did you read the API? What specifically confused you?
 
Ajay Xavier
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If one Thread needs to wait for another to complete it job then you can make use of join() method.

For eg. There are two threads Thread A and B. Thread A need to start it job after Thread B gets completed then mark the follwoing in
Thread A

b.join();

Thread A's stack will be added at the end of Thread B's stack.

Hope this would be helpful.

Regards,
Ajay.
 
Cate van Alphen
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ajay Xavier:
...
For eg. There are two threads Thread A and B. Thread A need to start it job after Thread B gets completed then mark the follwoing in
Thread A

b.join();



I am also a bit confused about join(). Where in Thread A do you put b.join();? Does Thread A start Thread B, or are they two threads in main() if so, how does Thread A know about Thread B?
[ June 16, 2006: Message edited by: Cate van Alphen ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've used them mostly with the concept of a main thread and a bunch of worker threads. The main thread joins each of the workers so we know all the workers have finished before the main thread goes on. But you really could think of any thread joining any other thread.

How does one thread get a reference to another? The same way any object gets ar eference to another ... a parameter, a variable, a global singleton, or whatever else you can think of.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!