jQuery in Action, 3rd edition
The moose likes Threads and Synchronization and the fly likes whose responsible for scheduling Threads ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "whose responsible for scheduling Threads ???" Watch "whose responsible for scheduling Threads ???" New topic

whose responsible for scheduling Threads ???

Nada Mohammed
Ranch Hand

Joined: Sep 22, 2000
Posts: 30
Hi ,
Who is responsible for scheduling threads ??programmer by using Threads
API or O.S. ??? in anther word , scheduling in java depend on real time system or depend on threads library or both??
note : i write program in java contain more than one threads and when i run the program the threads excute run method sequentially there is no interleave in the result but when i add sleep the run is interleaved so i hope i get any body explain for me why ???
Thanks a lot

[This message has been edited by Rahul Mahindrakar (edited December 12, 2000).]
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi Nada,
Although I'm no expert still I'll just try to answer your question as per my understanding.
java gives the programmer the liberty to create threads.
but what will be the behaviour of the threads as far as scheduling is concerned will totally depend upon the underlying OS.
when we create a thread e.g.
Thread t = new Thread();
then a thread object is created.
now when we write
the thread is added to the pool of ready threads i.e. those threads from where the os scheduler chooses the thread
to run.
so once we say t.start() our job is over now and how our threads will be running depends upon the particular O.S. only.

that's my understanding.
let's see what others think about it.

Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
How the order in which threads are executed is based on how the underlying OS implements time-slicing,scheduling. infact in the same machine (under same OS), the order may change at two different times. In cooperative multi-tasking, once a thread takes over the CPU, the other waiting thread gets the chance only if the waiting thread is of higher priority or the running thread gives the CPU voluntarily. So a low priority thread may have to wait a long time, if a higher priority thread has the CPU. IN a pre-emptive time slicing OS like win 98/NT, the low priority thread does not have to starve because of the round robin scheduling that the OS uses. However if we can't predict what will be the os on which the java application will be running, so its better to use Thread.sleep(millis), so that even if a high priority thread is running, it will go to sleep after some time, allowing the other low priority thread to get the CPU atleat for the 'millis' amount of time(milliseconds).

Author of JPhotoBrush Pro (www.jphotobrushpro.com)
I agree. Here's the link: http://aspose.com/file-tools
subject: whose responsible for scheduling Threads ???
It's not a secret anymore!