Java program for priority thread
KW.java
class KW extends Thread
{  
    public void run()
    {  
        System.out.println(Thread.currentThread().getName()+" Server Is Running...");       
    }  
    public static void main(String args[])
    {  
        KW t1=new KW();
        KW t2=new KW(); 
        KW t3=new KW(); 
        t1.setName("MongoDB");
        t2.setName("MySQL");
        t3.setName("Cassandra");
        t1.setPriority(Thread.MAX_PRIORITY);
        t2.setPriority(Thread.NORM_PRIORITY);
        t3.setPriority(Thread.MIN_PRIORITY);
        System.out.println("Thread Priority T1 "+t1.getPriority());
        System.out.println("Thread Priority T2 "+t2.getPriority());
        System.out.println("Thread Priority T3 "+t3.getPriority());
        t1.start(); 
        t2.start();
        t3.start();  
    }  
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Thread Priority T1 10 Thread Priority T2 5 Thread Priority T3 1 MongoDB Server Is Running... MySQL Server Is Running... Cassandra Server Is Running... kodingwindow@kw:~$
Advertisement