Java OCA OCP Practice Question 17

Question

Which one statement is always true about the following application?

 1. class MyClass extends Thread { 
 2.   MyClass() { //  w ww.  j ava2s. c o m
 3.     setPriority(10); 
 4.   } 
 5. 
 6.   public void run() { 
 7.     System.out.println( 
 8.       "Another thread starting up."); 
 9.     while (true) { } 
10.   } 
11. 
12.   public static void main(String args[]) { 
13.     MyClass hp1 = new MyClass(); 
14.     MyClass hp2 = new MyClass(); 
15.     MyClass hp3 = new MyClass(); 
16.     hp1.start(); 
17.     hp2.start(); 
18.     hp3.start(); 
19.   } 
20. } 
  • 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, thread hp1 will execute to completion, thread hp2 will execute to completion, then thread hp3 will execute to completion.
  • C. When the application is run, all three threads (hp1, hp2, and hp3) will execute concurrently, taking time-sliced turns in the CPU.
  • D. None of the above scenarios can be guaranteed to happen in all cases.


C.

Note

There is no way to predict how thread priority manipulation will affect the specific performance of individual threads.

Priority manipulation only affects overall statistical behavior.




PreviousNext

Related