This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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.
 
wood burning stoves
 
subject: Pls help.. Questions on Thread.