• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inter-Thread Communication  RSS feed

 
Sidharth Pallai
Ranch Hand
Posts: 137
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain me , how to make a thread wait until the other thread finishes.
My scenario is calling a external java class within my application and have it execute some operation.The critical point is that while the external thread continues its operation, the caller thread wouldn't interrupt it ie it should be in waiting state.
 
Mohd Fuzail
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check Thread API here and i think JOIN should serve your purpose
[ June 12, 2008: Message edited by: Mohd Fuzail ]
 
Sidharth Pallai
Ranch Hand
Posts: 137
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Fuzail,
Can yield() will be of any usefullness in my scenario, or how join will do it.Can you be bit precise.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sidharth:
Can yield() will be of any usefullness in my scenario, or how join will do it.Can you be bit precise.


No, yield() is not the thing you should be using. Yield just give a hint to the JVM that this thread is ready to give up CPU in favor of some other threads. It does not guarantee that this thread will resume only when a particular thread has finished. This is i guess what you want.

join() guarantees that the calling thread will wait till the thread on which the join has been called has indeed finished execution.

So, if you have two threads T1 and T2
T1 calls T2.join()
T1 suspends execution
T2 finishes execution
T1 resumes execution

Hope this answers your question.
BTW, this topic belongs to the Thread & Syncrhonization forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!