class MyThread extends Thread {
public MyThread(String name) {
super(name); //setName(name);
}
@Override
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println(getName()+" : "+i);
}
}
}
public class Demo {
public static void main(String args[]){
MyThread t1=new MyThread("One");
MyThread t2=new MyThread("Two");
MyThread t3=new MyThread("Three");
System.out.println("t1 : "+t1.getPriority()); //5
System.out.println("t2 : "+t2.getPriority()); //5
System.out.println("t3 : "+t3.getPriority()); //5
t1.setPriority(1); //Thread.MIN_PRIORITY
t2.setPriority(5); //Thread.NORM_PRIORITY
t3.setPriority(10); //Thread.MAX_PRIORITY
t1.start();
t2.start();
t3.start();
}
}
I wrote this code to check the priority in java threads. But It doesn't give the priority in every time this code execute. Please explain me why this happens? Is this the nature of Java threads or else?