Monday, March 2, 2015

Priority of Threads

By Default the priority of the thread is 5 and you can set the priority of the thread to minimum which is 1 and max which is 10. Below example illustrates the same.

package Threadspriority;

public class mainclass {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Thread t=new thread1();
  Runnable r=new thread2();
  
  t.start();  
  new Thread(r).start();
  System.out.println(t.getName());
  System.out.println("Priority of the thread by default"+t.getPriority());
  t.setPriority(t.MIN_PRIORITY);
  System.out.println("Priority of the thread after setting "+t.getPriority());
  t.setPriority(t.MAX_PRIORITY);
  System.out.println("Priority of the thread after setting "+t.getPriority());
 }

}

>>>
------------------------------------------------------------------------------------------------------------