Search your topic in Java2share
Home > FAQs
eXTReMe Tracker


Multi Threading FAQs


Untitled Document

Q21. Once we created a new Thread what about its priority?
Ans.  Whatever priority parent thread has the same will be inherited to the new child thread.
Q22.  How to get and set priority of a Thread?
Ans.    To get and set priority of a Thread, Thread class defines the following two methods:;

1.         Public final int getPriority();                                                                                                                                    

2.        Public final void setPriority(int priority);

Q23.   If we are trying to set priority of a Thread as 100 what will happen?
Ans.    If we are trying to set priority of a Thread as 100 then we will not get any compile time error but at the runtime we will get Runtime exception IllegalArgumentException. Because the valid range of the Thread priority is (1-10) only.

Q24.   If two threads having same priority then which thread will get chance first for execution?
Ans.   If two threads having same priority then which thread will get the chance first for execution decided by Thread Scheduler. It is the part of JVM and its behavior is vendor dependent and we can’t expect exact output.