Interview Questions

What are thread priorities?

Java Interview Questions and Answers (part 4)


(Continued from previous question...)

60. What are thread priorities?

Thread Priority range is from 1 to 10.
Where 1 is minimum priority and 10 is maximum priority.

Thread class provides variables of final static int type for setting thread priority.

/* The minimum priority that a thread can have. */
public final static int MIN_PRIORITY = 1;

/* The default priority that is assigned to a thread. */
public final static int NORM_PRIORITY = 5;
/* The maximum priority that a thread can have. */
public final static int MAX_PRIORITY = 10;


Thread with MAX_PRIORITY is likely to get more CPU as compared to low priority threads. But occasionally low priority thread might get more CPU. Because thread scheduler schedules thread on discretion of implementation and thread behaviour is totally unpredictable.

Thread with MIN_PRIORITY is likely to get less CPU as compared to high priority threads. But occasionally high priority thread might less CPU. Because thread scheduler schedules thread on discretion of implementation and thread behaviour is totally unpredictable.

setPriority() method is used for Changing the priority of thread.
getPriority() method returns the thread’s priority.

(Continued on next question...)

Other Interview Questions