Java Thread Priority in Multithreading

Last Updated : 30 Nov, 2026

Thread priority is a numerical value ranging from 1 to 10 that indicates the scheduling preference of a platform thread. It may influence the thread scheduler but does not guarantee execution order.

  • Platform threads normally inherit the priority of their creating thread.
  • Virtual threads have a fixed priority of 5, which cannot be changed.

Thread Priority Constants

The Thread class provides three predefined priority constants.

java_thread_priority

Setting and Getting Thread Priority

Java provides two methods to manage thread priorities.

  • setPriority(int priority) sets the priority of a platform thread.
  • getPriority() returns the current priority of a thread.

Example: Setting different thread priorities.

Java
class MyThread extends Thread{
    @Override
    public void run(){
        System.out.println(getName() + ": " + getPriority());
    }
}

public class Geeks {
    public static void main(String[] args){
        MyThread t1 = new MyThread();
        MyThread t2 = new MyThread();
        MyThread t3 = new MyThread();

        t1.setPriority(Thread.MIN_PRIORITY);
        t2.setPriority(Thread.NORM_PRIORITY);
        t3.setPriority(Thread.MAX_PRIORITY);

        t1.start();
        t2.start();
        t3.start();
    }
}

Output
Thread-1: 5
Thread-2: 10
Thread-0: 1

Explanation: The three threads are assigned different priorities and started using the start() method. Their execution order depends on the JVM and underlying operating system.

Note: Passing a priority outside the range of 1–10 to setPriority() throws IllegalArgumentException.

Thread Priority Inheritance

A newly created platform thread normally inherits the priority of the thread that creates it.

Java
public class Geeks{
    public static void main(String[] args){
        Thread.currentThread().setPriority(7);

        Thread t1 = new Thread();
        Thread t2 = new Thread();

        System.out.println(t1.getPriority());
        System.out.println(t2.getPriority());
    }
}

Output
7
7

Explanation: Both threads inherit priority 7 from the main thread.

Thread Priority and Scheduling

Thread priority provides a scheduling preference rather than a fixed execution sequence.

  • Higher-priority threads may receive scheduling preference.
  • Threads with equal priorities have no guaranteed execution order.
  • A higher priority does not guarantee faster execution.
  • Thread priority should not be used to control execution order or synchronization.

Related Article: Multithreading in Java.

Comment