WAP for setting priority of main thread

2 years ago
OOP Java

package threadpriority;

// Java program to demonstrate that a child thread gets same priority as parent class Mainthreadpriority extends Thread

{

public void run()

{

System.out.println("Inside run method");

}

 

public static void main(String[]args)

{

// main thread priority is 6 now

 

Thread.currentThread().setPriority(6);

 

System.out.println("main thread priority : " +

Thread.currentThread().getPriority());

 

Mainthreadpriority t1 = new Mainthreadpriority();

 

// t1 thread is child of main thread

// so t1 thread will also have priority 6.

System.out.println("t1 thread priority : " + t1.getPriority());

}

}

         

0
Bijay Satyal
Nov 3, 2021
More related questions

Questions Bank

View all Questions