• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread MIN/NORM/MAX PRIORITY

 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I sometimes get questions from mock exams asking the values of these 3 constants. I would always answer 1, 5, and 10 respectively because this is what is hardcoded in the Thread class. But I wonder if these values are really fixed. I don't see anything in the JLS or API docs telliing that they must have these values.
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that's up to the JVM implementation. There can be one implementation that only has from 1 to 5, so that's the reason you shouldn't rely on that when implementing threaded applications. If you choose a priority of 10, for instance, this thread might end up having the same priority as other in the range from 1 to 5.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Going back to my old friend KnB book, I found this in page 537


the setPriority() method is used on Thread objects to give threads a priority between 1(low) and 10(high), although priorities are not guaranteed, and not all JVMs use a priority range 1-10


[ August 21, 2003: Message edited by: Andres Gonzalez ]
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is not really about how the JVM would interpret the priority assigned to the Thread. It is really about the numbers themselves, the values assigned to these 3 constant fields. Is it possible for other implementations to use other values?
 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the constant field values at http://java.sun.com/j2se/1.4.1/docs/api/constant-values.html
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
However, note that if your JVM does not support priority values in the full range, when you do a getPriority() call it will be whatever the JVM decided to assign, not the number in the constants.
Bill
reply
    Bookmark Topic Watch Topic
  • New Topic