Java Thread Priority
In Java language, Each thread has a priority which schedules the thread with the help of the operating system.
Java thread priorities are within the range MIN_PRIORITY and MAX_PRIORITY. These values are 1 and 10, respectively. By default, every thread is given NORM_PRIORITY, which is currently 5.
- public static int MIN_PRIORITY
- public static int NORM_PRIORITY
- public static int MAX_PRIORITY

Syntax:
final void setPriority(int level) final int getPriority( )
Example:
public class ThreadPriority extends Thread{
public void run(){
System.out.println("Thread name is "+Thread.currentThread().getName());
System.out.println("Thread priority is "+Thread.currentThread().getPriority());
}
public static void main(String args[]){
ThreadPriority t1=new ThreadPriority();
ThreadPriority t2=new ThreadPriority();
ThreadPriority t3=new ThreadPriority();
t1.setPriority(Thread.MIN_PRIORITY);
t2.setPriority(Thread.MAX_PRIORITY);
t3.setPriority(Thread.NORM_PRIORITY);
t1.start();
t2.start();
t3.start();
}
}
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com