This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Pre emptive/time slicing

 
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?
 
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 ??
 
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.
 
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
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!