my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Questions about thread priority Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Questions about thread priority" Watch "Questions about thread priority" New topic
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Questions about thread priority
 
Similar Threads
Please give me reply.
threads priority
very urgent - threads
Threads
notify() vs notifyall()