Default priority of a thread is 5 (NORM_PRIORITY). The
value of
MIN_PRIORITY is 1
and the value of MAX_PRIORITY is 10.
|
Example
of priority of a Thread:
class TestMultiPriority1 extends Thread{
public void run(){
System.out.println("running thread name is:"+Thread.currentThread().g etName());
System.out.println("running thread priority is:"+Thread.currentThread().getPri ority());
}
public static void main(String args[]){
TestMultiPriority1 m1=new TestMultiPriority1();
TestMultiPriority1 m2=new TestMultiPriority1();
m1.setPriority(Thread.MIN_PRIORITY);
m2.setPriority(Thread.MAX_PRIORITY);
m1.start();
m2.start();
}
}
Output:
running thread
name is:Thread-0
running thread
priority is:10
running thread
name is:Thread-1
running thread
priority is:1
No comments:
Post a Comment