Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

doubt abt priorities in threads.......

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


output is not predictable...


then how the priorities work in threads?
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using KS & BB book for preparation then i am sure you won't have much problem in understanding the concept of thread priorities. The Threads chapter explains it pretty clearly.

I think you can be specific as to what are your doubts? How do you interpret the output to be?
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i red as there is no gaurantee behavior in that book...

but Is there anyway to get exact output according to the priorities?
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh you will normally get output according to the priority of the threads. But for SCJP you will have to consider all the exceptional cases so you will have to say that the output is unpredictable...
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
output is not predictable for many programs in threads....

ok thanks ankit....
 
Harvinder Thakur
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i guess you've answered the question:

i red as there is no gaurantee behavior in that book...



As far as i know there is no guaranteed way of getting an exact output using Thread priorities as it is solely jvm thread scheduler implementation dependent.

Maybe Henry can throw some more light on this.
 
author
Posts: 23879
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case, the threads are so short lived, I highly doubt that priorities are related at all -- it is more of which thread gets started first.

But to answer the question... priorities are mapped to the underlying priorities in the OS threading system. On some systems, the default priority is not enough. For example, Windows will allow a low priority thread to run over a high priority one, in order to avoid thread starvation. On other systems, certain adjacent priority levels are the same, just because there are less priority levels to map to.

So, think of priorities as a hint. The OS will try to honor it, and in most cases, the higher priority thread will get more and longer timeslices. But there is no guarantee that a high priority thread will finish first (or start first).

Henry
 
    Bookmark Topic Watch Topic
  • New Topic