my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Pls help.. Questions on Thread. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Pls help.. Questions on Thread." Watch "Pls help.. Questions on Thread." New topic

Pls help.. Questions on Thread.

Ernest Lee
Ranch Hand

Joined: Aug 20, 2001
Posts: 145
If a thread with lower priority is running, a new thread with higher priority become ready to execute, will the JVM stop the lower priority thread and run the thread with higher priority run automatically??
Or the lower prority will need to call yield() explicitly to make this happen??
If the higher priority is running and call yield(), will JVM select the lower priority thread?
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Ernest,
Good questions, but the answers are that each JVM designer can do what they want. The JVM specs don't specify how priorities are used by the JVM just that they exist and how they might be used.
The following quote sums it up.

Every thread has a priority. When there is competition for processing resources, threads with higher priority are generally executed in preference to threads with lower priority. Such preference is not, however, a guarantee that the highest priority thread will always be running,and thread priorities cannot be used to reliably implement mutual exclusion.

I agree. Here's the link:
subject: Pls help.. Questions on Thread.
It's not a secret anymore!