28.Thread Priority


class thrun implements Runnable
{
Thread t;
boolean runn = true;

thrun(String st,int p)
{
t = new Thread(this,st);
t.setPriority(p);
t.start();
}

public void run()
{
System.out.println(“Thread name : ” + t.getName());
System.out.println(“Thread Priority : ” + t.getPriority());
}

}

class Priority
{
public static void main(String args[])
{
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
thrun t1 = new thrun(“Thread1”,Thread.NORM_PRIORITY + 2);
thrun t2 = new thrun(“Thread2”,Thread.NORM_PRIORITY – 2);
System.out.println(“Main Thread : ” + Thread.currentThread());
System.out.println(“Main Thread Priority : ” + Thread.currentThread().getPriority());
}
}