This is question 2 of the RHE book chapter 7(
Thread), p228
2. which one statement below is always true about the following
application?
class HiPri extends Thread{
HiPri(){
setPriority(10);
}
public void run(){
System.out.println("Another thread starting up!");
while(true){} //HERE!!
}
public static void main(
String[] args){
HiPri hp1 = new HiPri();
HiPri hp2 = new HiPri();
HiPri hp3 = new HiPri();
hp1.start();
hp2.start();
hp3.start();
}
}
A. When the application is run, thread hp1 will execute, threads
hp2 and hp3 will never get the CPU;
B. When the application is run, all three threads will get to
execute, taking time-slicing turns in the CPU.
C. Either A or B will be true, depending on the underlying platform.
Answer given is C.
===========================================================
My question is: the line
while(true){} //Here!!
in the run method, should we consider this an infinite loop?
if so, then once any of the three hp1, hp2 or hp3 threads gets to
execute, the other two will not get an chance to run. Making
statement A and C incorrect but leaving B correct if time-slicing
is implemented.Any response is appreciated!