Thread Priority

class ThreadOne extends Thread
{
public void run()
{
try
{
for(int i=0;i<5;i++)
{
System.out.println("Thread 1 : i ="+i);
Thread.sleep(500);
}
}
catch(Exception e)
{

}
}
}

class ThreadTwo extends Thread
{
public void run()
{
try
{
for(int i=0;i<5;i++)
{
System.out.println("Thread 2 : i ="+i);
Thread.sleep(500);
}
}
catch(Exception e)
{

}
}
}
public class ThreadPriority {
public static void main(String args[])
{
ThreadOne a=new ThreadOne();
ThreadTwo b=new ThreadTwo();

System.out.println("Thread 1 Default Priority ="+a.getPriority());
System.out.println("Thread 2 Default Priority ="+b.getPriority());

a.setPriority(Thread.MIN_PRIORITY);
b.setPriority(Thread.MAX_PRIORITY);

System.out.println("Thread 1 Default Priority ="+a.getPriority());
System.out.println("Thread 2 Default Priority ="+b.getPriority());
}

}


No comments: