What is the mechanism of Thread Priority & Thread Scheduler? How do Threads with various priority levels behave in time-sliced and non-time-sliced environments?

Ron Kurr

Mapping of Java's 10 thread priorities to the underlying OS is platform dependent. For example, NT has 7 priorities which needs to get mapped to Java's 10 -- and you don't really know what Java priority maps to what NT priority. NT also "priority boosts" threads on occassion, which temporarily adjusts a thread's priority without you actually knowing about it. You might consider not relying on anything other than Thread.MAX_PRIORITY, Thread.MIN_PRIORITY and Thread.NORM_PRIORITY for your scheduling needs.

To answer your second question, I think you are referring to green threads and native threads. Green Threads is the cooperative thread model where the JVM handles the scheduling of threads. Native Threads is the preemptive threading model which use the OS to schedule threads. In the Green Thread model, threads only give up control if they call yield(), sleep() or make a blocking IO call. Under the Native Thread model, you never know when your thread is going to be interrupted and must code accordingly, using synchronized statements. Unless you target your code to a particular platform, you need to code such that it behaves in a cooperative as well as a preemptive environment.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact