JAVA | Explain thread priority and method to get and set priority values.

Thread Priority: In java each thread is assigned a priority which affects the order in which it is scheduled for running. Thread priority is used to decide when to switch from one running thread to another. Threads of same priority are given equal treatment by the java scheduler. Thread priorities can take value from 1-10. 

Following are integer constants for Thread Priority: 
1) MIN_PRIORITY= The minimum priority of any thread(int value of 1)
2) NORM_PRIORITY= The normal priority of any thread(int value of 5)
3) MAX_PRIORITY= The maximum priority of any thread(int value of 10)

1. setPriority: 
Syntax: public void setPriority(int number);
This method is used to assign new priority to the thread. 
2. getPriority: 
Syntax: public int getPriority(); 
It obtain the priority of the thread and returns integer value. 

Post a Comment

0 Comments