I always thought a.) whether JVM runs pre-emptively or in a time slicing manner to be purely a platform specific issue. b). we have no control over which thread will be run whatsoever. But Sun's tutorial says: -Scheduling of the CPU is fully preemptive. If a thread with a higher priority than the currently executing thread needs to execute, the higher priority thread is immediately scheduled. (This seems to imply that we can choose which thread will run by setting them with highest priority) -The Java runtime will not preempt the currently running thread for another thread of the same priority. In other words, the Java runtime does not time-slice. However, the system implementation of threads underlying the Java Thread class may support time-slicing. Do not write code that relies on time-slicing. Can anyone please help me?
I believe what Sun was saying is that threads of higher priority will preempt threads of lower priority and run. So the scheduler will always put higher priorty threads first. But some systems will use time sharing so that one higher priority thread will not consume all of the systems resoureces. It seems this is especially important when resources get low. So, it will stop that higher priority thread and let some of the lower priority threads kick in and do there thing for a while, and then go back to the higher thread. Basically what I am getting from this is that you can't rely on the priority of the thread to used in algorithms that are sensitive. You can't say which thread will actually run all the time, eventhough the higher priority thread will be run first a lot of the times.