public class PriorityOfThread extends Thread {
@Override
public void run() {
System.out.println("Child Thread running");
}
public static void main(String[] args) {
//Creating a new thread
PriorityOfThread pot = new PriorityOfThread();
//invoking the thread
pot.start();
//getting current thread priority
System.out.println(
"main(Parent) thread Priority :" + Thread.currentThread().getPriority()
);
//getting new thread priority
System.out.println("Child thread Priority" + pot.getPriority());
//setting current thread priority
Thread.currentThread().setPriority(10);
//Creating another thread
PriorityOfThread pot1 = new PriorityOfThread();
//invoking the thread
pot1.start();
System.out.println("after invoking setPriority method");
//getting current thread priority after invoking setPriority method
System.out.println(
"main thread priority :" + Thread.currentThread().getPriority()
);
//getting new created(child thread) thread priority
//after setting priority of main thread(Parent thread)
System.out.println("Child thread Priority :" + pot.getPriority());
//Child inherits its priority from its parent i.e main(in case of this thread)
System.out.println("Second Child thread Priority :" + pot1.getPriority());
}
}