• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Join method in mutithreadng

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I understand, the join method lets the compiler knows that it should let the specified thread finish completion and then join the other threads.  So, question is does join put all other threads in a sleep state or a wait state.  As I understand it, sleep is a modal state, that is it causes execution to pause completely, that is all threads are paused until the lock is released.  Wait is a method that is not modal, it does not stop execution of other threads.  Am I right?

Also, what is the difference between setting .join on a thread, and setting the priorities on all the threads so that the priority of the thread which should be executed to completion first is set higher than the priories of the other threads?  Say there are 3 threads, t1, t2 and t3.  Wouldn't both ways t1.join() vs t1.setPriority(10); t2.setPriority(2); and t3.setPriority(2); cause t1 to execute first, and then let t2 and t3 start after t1 has completed?  
 
Marshal
Posts: 70234
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding discussion to our threading forum.

Java™ Tutorials link. Have you been through the API documentation?
 
Marshal
Posts: 25811
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shashank Gokhale wrote:As far as I understand, the join method lets the compiler knows that it should let the specified thread finish completion and then join the other threads.



No. It doesn't direct the compiler to do anything, first of all. You're asking about run-time behaviour. And as you'll find when you read the API documentation, it simply waits for the thread on which the join method is called to die. That's all. Nothing happens to any other threads.

So, question is does join put all other threads in a sleep state or a wait state.  As I understand it, sleep is a modal state, that is it causes execution to pause completely, that is all threads are paused until the lock is released.  Wait is a method that is not modal, it does not stop execution of other threads.  Am I right?



No. It doesn't do anything to any other threads.

Also, what is the difference between setting .join on a thread, and setting the priorities on all the threads so that the priority of the thread which should be executed to completion first is set higher than the priories of the other threads?  Say there are 3 threads, t1, t2 and t3.  Wouldn't both ways t1.join() vs t1.setPriority(10); t2.setPriority(2); and t3.setPriority(2); cause t1 to execute first, and then let t2 and t3 start after t1 has completed?  



No. Calling join() on a thread has no effect on any other threads.
 
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic