Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Priority  RSS feed

 
Vikrama Sanjeeva
Ranch Hand
Posts: 760
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun Java 2 Tutorial says,

The Java runtime supports a very simple, deterministic scheduling algorithm known as fixed priority scheduling. This algorithm schedules threads based on their priority relative to other runnable threads.

This means that JVM support time slicing or roun-robin algorithm.
On the other hand it says,

The Java runtime system's thread scheduling algorithm is also preemptive.

Please make me one thing clear,
Preemtive & Time-Slicing or Round-Robin are algorithms which OS uses.Does these algorithms are used by JVM too?.If yes then, whose algorithm will be applied to the threads created from main().
Another thing is that,the actual JVM designed by SUN uses which algorithm.?
Bye.
Viki.
------------------
Count the flowers of ur garden,NOT the leafs which falls away!
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on which JVM you use and what settings you give it, you may get "native" threads or "green" threads. With the former, you get whatever threading and prioritisation algorithm the platform likes. With the latter, you get a simple implementation of thread-like behaviour, actually on one platform thread. I can't remember the details of "green" threads, but it will be documented (I have Java Threads book, for instance).
But why do you ask this question? In my opinion, it is fine to want to know how things work, for interest, or to understand problems. But Java makes very few guarantees about how threading will behave, and it goes against the spirit of the language to make your application depend on the particular way that threading works on a particular platform. For instance, thread priorities are purely a suggestion by the developer of which thread should get priority; the spec doesn't guarantee that the JVM will take much notice.
In general, one should strive to design one's application to be independent of the way that threading works. And if this is truly impossible in a particular application, perhaps Java is the wrong language?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!