This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Pls help.. Questions on Thread." Watch "Pls help.. Questions on Thread." New topic
Author

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.

Regards,
Manfred.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Pls help.. Questions on Thread.
 
Similar Threads
threads and priority - guarenteed?
Marcus Green mock exam - 2 #24
Yielding Threads
Question from k&B's masterexam about yield()???????
Thread yield method