Thread Priority MCQ

Java Multithreading MCQ Part-5 | Thread Priority MCQ | Also see:- Define Thread in Java Multithreading Interview Questions

Q1) What is the valid range of priority of a thread in Java multi-threading?

a) 1 to 10
b) 0 to 10
c) 0 to 9
d) 1 to 9

View Answer Answer:- a) 1 to 10

Q2) Which is the minimum priority of the Thread?

a) Thread.LOW_PRIORITY
b) Thread.MIN_PRIORITY
c) Thread.NORM_PRIORITY
d) Thread.MINIMUM_PRIORITY

View Answer Answer:- b) Thread.MIN_PRIORITY

Q3) What is the value of Thread.NORM_PRIORITY?

a) 1
b) 5
c) 6
d) 9

View Answer Answer:- b) 5

Q4) Which of these are invalid thread priorities?

1) Thread.MIN_PRIORITY
2) Thread.HIGH_PRIORITY
3) Thread.NORM_PRIORITY
4) Thread.LOW_PRIORITY
5) 0
6) 1
7) 10

Options:-

a) 2 & 5
b) 2, 4 & 5
c) 2, 3, 4 & 5
d) All are valid

View Answer Answer:- b) 2, 4 & 5

Among these options Thread.HIGH_PRIORITY, Thread.LOW_PRIORITY and 0 are the invalid thread priority.

Q5) There are 4 threads given below priorities. If they are waiting for execution then what can be the order of getting a chance to execute?

ThreadPriority
t18
t26
t37
t44

a) t1 > t2 > t3 > t4
b) t4 > t3 > t2 > t1
c) t1 > t3 > t2 > t4
d) t4 > t2 > t3 > t1

View Answer Answer:- c) t1 & t3 & t2 & t4

The thread having high priority will get a chance first.

Q6) Which of the following method calls is invalid?

a) t1.setPriority(5)
b) t1.setPriority(1)
c) t1.setPriority(12)
d) t1.setPriority(9)

View Answer Answer:- c) t1.setPriority(12)

In the setPriority(int p) the passed value must belong to the thread priority range (1 to 10) else we will get an IllegalArgumentException.

Q7) What is the default priority of a thread?

a) 1
b) 5
c) Inherit from Parent
d) Random value within 1 to 10

View Answer Answer:- c) Inherit from Parent

The default priority of the thread is inherited from the parent thread. Child thread will get the same priority as parent thread.

Q8) What is the default priority of the main thread?

a) 1
b) 5
c) 10
d) Random value within 1 to 10

View Answer Answer:- b) 5

Q9) Find the output of the below program?

public class Test extends Thread {
   public static void main(String[] args) {
      System.out.print(Thread.currentThread().getPriority()+" ");
      Thread.currentThread().setPriority(9);
      Test t = new Test();
      System.out.println(t.getPriority());
   }
}

a) 5 9
b) 5 5
c) 9 5
d) 5 10

View Answer Answer:- a) 5 9

The default priority of the main thread is 5. The thread t1 is created by the main thread therefore the main thread is the parent thread and t1 is the child thread. The thread priority of the main thread is set to 9, then the child thread is created. The priority of the child thread inherits from the parent thread. Hence the priority of child thread is 9.

Q10) Find the output of the below program?

public class Test {
   public static void main(String[] args) {
      System.out.println(Thread.MAX_PRIORITY);
   }
}

a) 9
b) 10
c) 0
d) 1

View Answer Answer:- b) 10

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *