Write a Thread setPriority() program

Write a Thread setPriority() program

Minimum Priority Thread
class ThDemo  extends Thread
{
    public void run()  
    {    
        System.out.println("Priority of thread is: "+Thread.currentThread().getPriority());    
    }   
    
}
public class Demp3
{
    public static void main(String args[])
    {
        ThDemo d1=new ThDemo();
        d1.setPriority(Thread.MIN_PRIORITY); 
        d1.start();
       
        
    }
}


Output:

Priority of thread is: 1


Normal Priority Thread
class ThDemo  extends Thread
{
    public void run()  
    {    
        System.out.println("Priority of thread is: "+Thread.currentThread().getPriority());    
    }   
    
}
public class Demp3
{
    public static void main(String args[])
    {
        ThDemo d1=new ThDemo();
        d1.setPriority(Thread.NORM_PRIORITY); 
        d1.start();
    }
}


Output:

Priority of thread is: 5


Maximum Priority Thread
class ThDemo  extends Thread
{
    public void run()  
    {    
        System.out.println("Priority of thread is: "+Thread.currentThread().getPriority());    
    }   
    
}
public class Main
{
    public static void main(String args[])
    {
        ThDemo d1=new ThDemo();
        d1.setPriority(Thread.MAX_PRIORITY); 
        d1.start();
    }
}


Output:

Priority of thread is: 10


Multi Threading In Java



More Questions


220 . Write a Java-program to Remove spaces in a given string ?
221 . Write a Java-program to Remove letters in a given string ?
222 . Write a Java-program to Remove numbers in a given string ?
223 . Write a Java-program to print duplicate characters from the string ?
224 . Write a Java-program to print unique(distinct (or non-repeating characters) ) characters from the string ?
225 . Write a java program How to check if two strings are anagrams of each other?
226 . How to reverse a string in Java without using the reverse method ?
227 . How to count the occurrence of the given character in a string?
228 . How to check if a string is a palindrome?
229 . How to count the number of words in a given string sentence?
230 . How to reverse the words from the given string sentence?