| Author |
Questions about thread priority
|
Alton Hernandez
Ranch Hand
Joined: May 30, 2003
Posts: 443
|
|
|
If high priority alone does not guarantee a thread to be chosen among competing ready-to-run threads, then what is the purpose of the setPriority() method? Does it serve just a hint to the JVM?
|
 |
sonu sharma
Greenhorn
Joined: May 17, 2003
Posts: 24
|
|
the high priority will make it have a preference over all other threads of lower prority. Hope this helps Sonu
|
 |
Andres Gonzalez
Ranch Hand
Joined: Nov 27, 2001
Posts: 1561
|
|
Originally posted by sonu sharma: the high priority will make it have a preference over all other threads of lower prority.
Not necessarily.... I'd say it depends on the implementation of the JVM, and how it handles that. Some virtual machines can handle priorities one way and others will not care about it. That's why you should never rely on that when you program. As alton wrote, I'd say it is just a hint, a suggestion to the JVM, but nothing is guaranteed in here. my $0.02 [ July 01, 2003: Message edited by: Andres Gonzalez ]
|
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
|
 |
Alton Hernandez
Ranch Hand
Joined: May 30, 2003
Posts: 443
|
|
From Java tutorial
The higher the integer, the higher the priority. At any given time, when multiple threads are ready to be executed, the runtime system chooses the runnable thread with the highest priority for execution. Only when that thread stops, yields, or becomes not runnable for some reason will a lower priority thread start executing. If two threads of the same priority are waiting for the CPU, the scheduler chooses one of them to run in a round-robin fashion. The chosen thread will run until one of the following conditions is true: * A higher priority thread becomes runnable. * It yields, or its run method exits. * On systems that support time-slicing, its time allotment has expired.
It seems that different books has its own take on the role of priority to thread scheduling.
|
 |
 |
|
|
subject: Questions about thread priority
|
|
|