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.
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.
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
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