File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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.