Hi,
I have a doubt
There are 10 different threads in runnable state. Each having priority 1 to 10. How does the CPU schedules or executes these threads?
Thanks, Ravi
Hi,
I have a doubt
There are 10 different threads in runnable state. Each having priority 1 to 10. How does the CPU schedules or executes these threads?
Thanks, Ravi
Mainstream Java implementations use "native threads", which means that thread scheduling is done through the operating system. Java thread priorities simply map to OS-specific values. You should read your OS documentation to figure out what those levels mean, though. :-)
The OS has a thread scheduler that will (using an algorithm) decide based on priority and a few other factors, which thread will be run next. If you have a multi-core system, then each CPU can take a thread for it's account.
There's also the fact that a thread gets a slot of time, and then gets switched out for another thread and has to wait its turn again.
But thread scheduling is an Operating System function.
I hope that gives you an answer to your question.
Since when did this place replace google?
google search for Java thread scheduling, first result:
http://lass.cs.umass.edu/~shenoy/courses/fall01/labs/talab2.html
It is worth noting, that windows ignores raised priorities, unless you are Administrator and on Linux all priorities are ignored unless you are root.
Generally, playing with thread priorities is not very useful.