The question is: What is the output of trying to compile and run the following code? The Options are: A: 5 1 B: 5 5 C: 1 1 D: The code compiles but throws runtime exception at //1 since you cannot setPriority after start(). The ANSWER is: A The explaination is: The setPriority method should be called before the thread has been started in order to take effect. You can call setPriority method after the thread starts though, where the calling does not affect the thread priority. My Question is: If calling setPriority after the thread starts doesn't take effect, why does getPriority() on line 2 returns 1 instead of 5? Can someone kindly explain?
posted 14 years ago
Q : Can setPriority() change the priority of an already up and running thread ? Ans: Yes! It can change! As long as the currently running thread has the rights to the change the priority if the thread it desires to change. (There is some Accesscheckbeing done in the setPriority call- Look into API) Tried a simple code .. by putting a run method in ur above Question. Worked fine and prints 5,1 Jennifer