• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

threads and priority - guarenteed?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic