How to set or change priority of Main Thread?

As already specified, you need to use setPriority() and getPriority() methods of Thread class to change and to retrieve priority of a Thread. However, first we need to get the Thread object of main Thread. This can be achieved using Thread.getCurrentThread(), which returns Thread object of the current Thread. Below is snippet of code

public class MainThreadPriority {
	public static void main(String[] args) {
		Thread t = Thread.currentThread();
		System.out.println("Priority of "+t.getName()+" thread is: "+t.getPriority());
		t.setPriority(Thread.MAX_PRIORITY - 2);
		System.out.println("Now, Priority of "+t.getName()+" thread is: "+t.getPriority());

You may also like to read:
All Threads examples

How to Set priority to a Thread

By default all the threads created, get medium priority, unless a specific priority explicitly is set to the thread. Below are the priority related constants provided in Thread class.
Thread.MIN_PRIORITY (value is 0)
Thread.NORM_PRIORITY (value is 5, which is default priority)
Thread.MAX_PRIORITY (value is 10)

Any numeric value between 0 and 10 can be set as priority to a Thread. Below are priority related methods provided in Thread class
void setPriority(int priority);
int getPriority();

A thread with high priority gets allocated with more CPU time, compared to threads with relatively low priority threads. Hence a thread with high priority threads executes faster, compared to low priority threads.

class NewThread2 implements Runnable{
	String name; //name of Thread
	Thread t;
	NewThread2(String threadname,int priority){
		t = new Thread(this,name);
		System.out.println("New thread:"+t);
	public void run(){
			for(int i=50;i>0;i--)
		}catch(Exception ie)
		System.out.println(name+" Exiting");

public class ThreadPriority {
	public static void main(String args[])
	//start the threads

	NewThread2 nt2=new NewThread2("Two",Thread.MAX_PRIORITY);
	NewThread2 nt3=new NewThread2("Three",3/*Thread.NORM_PRIORITY*/);
	NewThread2 nt1=new NewThread2("One",Thread.MIN_PRIORITY);
	}catch(Exception ien)
	System.out.println("main thread Interrupted");
	System.out.println("Thread One Alive?"+nt1.t.isAlive());
	System.out.println("Thread Two Alive?"+nt2.t.isAlive());
	System.out.println("Thread Three Alive?"+nt3.t.isAlive());
	System.out.println("Main thread has exited");
	System.out.println("main thread Exiting");