if the priority for the thread is not specified during creation whaat is the priority of that thread? is it normal priority set by the constant NORM_PRIORITY or is it that the priority is the same as the priority of the thread that creates it...please answer soon thank you in advance gayathri
hi there, according the Khalid's book p.284-- If no explicit thread priority is specialed for a thread, it's given the default priority of 5(Thread.NORM_PRIORITY) also, a thread inherits the priorty of its parent thread. usually the thread scheduler decides to let the thread with the highest priority in the Ready-to-run state to get CPU time. hope this help. good weekend. ^__^* martha
Joined: Jan 29, 2001
thank you all...but still, iam confused... i read from khalid that thread is set to normal priority but in mock exams they say its the parent threads priority... so if i have to answer in exam which one should i choose? for eg: state true or false if a thread is not assigned a priority during creation the priority assigned to it is Thread.NORM_PRIORITY please clear my doubt soon as iam taking the exam tomorrow
hai! All Thread including current main thread are set to normal priority(ie serPriority as 5) initially. So obviously it can be answered as "TRUE". <blink> s.a.kugan</blink> ------------------ s.a.kugan
Yes, I agree, it would be TRUE because inheriting priority from the creating thread IS setting a priority at creation. So you can infer into the question: If a thread is not assigned a priority during creation [i.e. the thread does not inherit its priority from another thread] the priority assigned to it is Thread.NORM_PRIORITY Of course the question this raises is when would a thread NOT inherit priority from its creating thread? (Other than in the case of the <h4>main()</h4> thread)... ------------------
In my opinion, every thread instance, is a member of excactly one thread group. A thread Group can have both threads and other thread Groups as its member. when a Java application is started, the JVM creates the main thread group as a member of "system thread group". A main thread is created in this main thread group to run the main() method of the application. If main() method spawns a thread, that thread INHERITS the user-thread status of the original thread (main), including its PRIORITY. By Default, all new user-created thread and thread group will become the member of this main thread group UNLESS another THREAD GROUP is passed as the first argument of the new statement constructor method. for example : ThreadGroup javaRanch = new ThreadGroup("MyTHREADGROUP"); Thread thread = new Thread(javaRanch, "MyThread"); You create a "thread", and this thread is a member of "javaRanch" ThreadGroup. By doing this, "thread" will inherits all status from javaRanch Thread Group, including the PRIORITY. so i choosed "FALSE".