• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

default Thread priority

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
What is default Thread priority (Note that I am not talking abt. NORM_PRIORITY) ?
J@Whiz says:The range of Thread priority in java is 1-10. The minimum priority is 1 and the maximum is 10. The default priority of any thread in java is 5.
JQPLUS says that it is not allways but most of the time .
Suppose, the q. is :
What is the default priority of any thread in Java ?
What will be the answer !!!
wht. u say ?
Ratul Banerjee.
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jdk say's the default priority or normal priority of a thread is 5 which in any case u know's it.Now the thing to look at is when u create a child thread it get's the priority of a parent thread.Suposse u created a thread inside the main method, before creating a thread inside a main method u set the priority of your main to 10 then your chid thread will also get the same priority i.e 10.
 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ratul...,
first you must understand :
Every thread instance is a member of exactly one ThreadGroup, A ThreadGroup can have both threads and other thread groups.
for example :
When a java application is started, the JVM creates the main ThreadGroup as a member of the system ThreadGroup. By Default, all new-user created threads will become the member of this main ThreadGroup UNLESS another ThreadGroup is passed as the first argument of the new statement's constructor method.
see below :
##########
ThreadGroup anotherTG = new ThreadGroup("MyThreadGroup");
anotherTG.getMaxPriority(); //will return 10
note: Every ThreadGroup has a Maximum Priority (10).
anotherTG.setMaxPriority(7); //set the max priority to 7
##########
Thread X = new Thread(anotherTG, "MyThread");
note: this become a member of anotherTG NOT main ThreadGroup.
if you use method X.getPriority(), by default JVM will always give you 5, you see not 7.
##########
supposse you want to change the priority of X, you can use setPriority() method :
X.setPriority(number);
note: the number MUST be a legal range 1-10, if number is larger than the Maximum Priority of anotherTG = 7, 7 will be used as a priority.
##########
So if you create thread on main(), you will get the priority of main ThreadGroup. (that is 5).
hope that helps
stevie

 
ratul banji
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nitin and Stevie,
MANY MANY THANKS FOR UR EXPLANATION.
Ratul
 
Enthuware Software Support
Posts: 4667
51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As other have explained, the right answer to you question is, the default priority of a thread is same as the priority of the thread that created this thread.
So you cannot say whether it is 0 1 5 or 10 or NORM_PRIORITY.
-Paul.
------------------
Get Certified, Guaranteed!
(Now Revised for the new Pattern)
www.enthuware.com/jqplus

Try out the world's only WebCompiler!
www.jdiscuss.com
 
ratul banji
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANKS Paul
 
reply
    Bookmark Topic Watch Topic
  • New Topic