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).]
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
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).
Author of JPhotoBrush Pro (www.jphotobrushpro.com)