aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes default Thread priority Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "default Thread priority " Watch "default Thread priority " New topic
Author

default Thread priority

ratul banji
Ranch Hand

Joined: Mar 15, 2001
Posts: 108
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.
nitin sharma
Ranch Hand

Joined: Feb 24, 2001
Posts: 290
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.
Stevie Kaligis
Ranch Hand

Joined: Feb 04, 2001
Posts: 400
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

Joined: Mar 15, 2001
Posts: 108
Hi Nitin and Stevie,
MANY MANY THANKS FOR UR EXPLANATION.
Ratul
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3293
    
    7
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


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
ratul banji
Ranch Hand

Joined: Mar 15, 2001
Posts: 108
THANKS Paul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default Thread priority