Forums Register Login

whose responsible for scheduling Threads ???

+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
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
t.start();
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.
regards
deekasha



+Pie Number of slices to send: Send
hi,
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).
Your mind is under my control .... your will is now mine .... read this tiny ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1218 times.
Similar Threads
When you run a program how many threads will create ?.
More Java 5 Questions
Thread q from RHE book
Concurrent behavior of threads
Questions about locks
Will Thread release the lock it holds when it enters sleep state?
threads: time-sliced versus preemptive
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:07:11.