• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Sheduler

 
Mahendra Kamble
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I wanted to know where the thread sheduler resides on a machine or when we use threads O.S shedular or JVM shedular is used for sheduling threads
------------------
Mahendra Kamble
Software Engineer
 
Neeraj Thakkar
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The scheduling of threads is done by the OS's scheduler. So once you start a number of threads from your program which thread will get its time in which order is taken care entirely by the scheduler of OS and not that by JVM
 
Rahul Rathore
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, as Neeraj says, thread scheduling is platform dependent. This is a weakness of the Java programming language. There is no guarantee that multithreaded programs will work identically on all virtual machines.
Consider for example that we can set priorities of thread in java. But there is no guarantee that the thread-scheduler will respect priorities. Theoretically it is possible that a thread-scheduler picks up a thread randomly, or keeps picking the first-available thread. And even if the operating system respects thread priorities, it may have fewer/more priority levels than those available in Java. Thus while mapping priority levels to the system's priority levels many priority differences may be lost i.e. originally lower priority threads, may get a priority which is the same as originally higher priority threads. Similarly there is no guarantee that the system will respond to the Thread.yield(). The scheduler may keep reactivating the same thread.
And it is for this platform-dependence that a selfish thread (eg. a thread is executing a long loop without any calls to sleep() or yield()) will prevent other threads from executing on a Solaris green threads implementation, but cannot do so on Windows, because Windows scheduler does time-slicing ensuring that all threads get a fair chance to run.
 
James Du
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a spectator, i really feel i could benefit much from the topic.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!