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

regarding join()

 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

thread on which join() is invoked should finish the task and then the calling thread will continue its execution.



But in the above code have have called join() in Mythread so calling thread main() have to finish the execution ,yes it has finished the task of main() thread but child thread task is not finished, it will stop.

Question:
1. Is there any way that join() should be used in certain threads or pattern only?

Please clarify it, thanks.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
veena bijur wrote:But in the above code have have called join() in Mythread so calling thread main() have to finish the execution ,yes it has finished the task of main() thread but child thread task is not finished, it will stop.

You call join() on the MyThread instance, inside the MyThread instance - which means the thread blocks until it (itself) is finished (or interrupted). This can never work: MyThread will wait until MyThread is finished, but MyThread can't finish because it is waiting. So your application will most likely hang forever.

Question:
1. Is there any way that join() should be used in certain threads or pattern only?
Is there a way it should be used? Yes, you call it on a different thread when you want to wait for that thread to finish. You never call it on the current thread, because then it can never return.
 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks a lot, now i am clear with the concept.

Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic