Thread Priority:
- public static int MIN_PRIORITY=1
- public static int NORM_PRIORITY=5
- public static int MAX_PRIORITY=10
Example:
class Test implements Runnable{
public void run(){
System.out.println("Priority of current thread="+Thread.currentThread().getPriority());
//getting default priority
}
}
public class GetPriorityDemo{
public static void main(String[] args) {
Test t=new Test();
Thread t1=new Thread(t);
t1.start();
}
}
public void run(){
System.out.println("Priority of current thread="+Thread.currentThread().getPriority());
//getting default priority
}
}
public class GetPriorityDemo{
public static void main(String[] args) {
Test t=new Test();
Thread t1=new Thread(t);
t1.start();
}
}
Set Priority in java:
class Test1 implements Runnable{
public void run(){
System.out.println("Priority of current thread="+Thread.currentThread().getPriority());
}
}
public class SetPriorityDemo{
public static void main(String[] args) {
Test t=new Test();
Thread t1=new Thread(t);
t1.setPriority(4);//set priority
t1.start();
//Thread.yield();
}
}
public void run(){
System.out.println("Priority of current thread="+Thread.currentThread().getPriority());
}
}
public class SetPriorityDemo{
public static void main(String[] args) {
Test t=new Test();
Thread t1=new Thread(t);
t1.setPriority(4);//set priority
t1.start();
//Thread.yield();
}
}