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?
posted 14 years ago
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.