Java Thread Priorities

Priority In Java:

 java.lang.Thread.MIN_PRIORITY = 1

java.lang.Thread.NORM_PRIORITY = 5
java.lang.Thread.MAX_PRIORITY  = 10

package com.company;


class MyThr extends Thread{
public MyThr(String name){
super(name);
}
public void run(){
System.out.println("Thank you " + this.getName());
}
}
public class tuts {
public static void main(String[] args) {
MyThr t1 = new MyThr("Aryan1");
MyThr t2 = new MyThr("Aryan2");
MyThr t3 = new MyThr("Aryan3");
MyThr t4 = new MyThr("Aryan4");
MyThr t5 = new MyThr("Aryan5 (Most Important)");
t5.setPriority(Thread.MAX_PRIORITY);
t1.setPriority(Thread.MIN_PRIORITY);
t2.setPriority(Thread.MIN_PRIORITY);
t3.setPriority(Thread.MIN_PRIORITY);
t4.setPriority(Thread.MIN_PRIORITY);
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
}
}

Comments

Popular posts from this blog

Creating a Thread by Extending Thread class

Constructors from Thread class in Java