Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

regarding join()  RSS feed

 
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.
 
Bartender
Posts: 4179
22
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.
 
We're all out of roofs. But we still have tiny ads:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!