• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pre emptive/time slicing

 
ricky gonzalez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
ms
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even i am confused about this ?? If scheduler does everything then why do we have priorties ??
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I also agree with bill.
we can assign priority to threads but whether it wil be efective or not will depend upon whether scheduler respects the priority or not.

although in most of the cases we can expect that high priority thread will be running first but we certainly can't be sure about it because after all it is scheduler's decison.
regards
deekasha
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!