Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

threads and priority - guarenteed?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I think I read that if a thread is running and there is another one with higher priority in the pool, the one running will wait and the higher priority one will run, this done by the scheduler. But this is not for sure.

But then I have that: the guarantee that we have is that the running thread will have the same or higher priority than the ones in the pool.

Aren't the two above opposite? which one is true? will we ever have a lower priority running while higher priority wait? Is the guarantee always true only if we do yield()?.

Thank you.
 
author
Posts: 23868
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Monica Moncho:
hi,

I think I read that if a thread is running and there is another one with higher priority in the pool, the one running will wait and the higher priority one will run, this done by the scheduler. But this is not for sure.

But then I have that: the guarantee that we have is that the running thread will have the same or higher priority than the ones in the pool.

Aren't the two above opposite? which one is true? will we ever have a lower priority running while higher priority wait? Is the guarantee always true only if we do yield()?.

Thank you.



What you are describing is pre-emptive sheduling, if you have a high priority thread that goes into a blocked state, then a lower priority thread will run. As soon as the high priority thread reenters the runnable state, it will run. And yes, this is done by the scheduler.

Your second paragraph is basically describing the same thing... but I would caution the word "guarantee", it is not guaranteed by the JVM. Specifically:

- On some older JVMs, or JVMs on OS that doesn't support this type of scheduling, there can be a lag before the higher priority thread becomes the currently running thread.
- Most JVMs uses the underlying threading system... so for Windows, it will try to make sure every thread gets a time slice, including a lower priority thread when there is a higher priority thread that is runnable.

Henry
 
Monica Moncho
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!

I hope I'll try to understand even the questions on the test :-)

But I'll remember that guarantee is too much to say about threads.
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!