You are on page 1of 3

Thread Priority

import java.io.*;
class thread1 extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println("calling from thread1");
}
System.out.println("quitting thread1");
}
}
class thread2 extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println("calling from thread2");
}
System.out.println("quitting thread2");
}
}
class thread3 extends Thread
{
public void run()
{
for(int i=1;i<=5;i++)
{
System.out.println("calling from thread3");

}
System.out.println("quitting thread3");
}
}
class threaddemo
{
public static void main(String args[])
{
thread1 t1=new thread1();
t1.setPriority(Thread.MAX_PRIORITY);
t1.start();
thread2 t2=new thread2();
t2.setPriority(Thread.MIN_PRIORITY);
t2.start();
thread3 t3=new thread3();
t3.setPriority(Thread.NORM_PRIORITY);
t3.start();
}
}

OUTPUT:
D:\raj>javac threaddemo.java
D:\raj>java threaddemo
calling from thread1
calling from thread1
calling from thread1
calling from thread1
calling from thread1
quitting thread1
calling from thread3
calling from thread3
calling from thread3
calling from thread3
calling from thread3
quitting thread3
calling from thread2
calling from thread2
calling from thread2
calling from thread2
calling from thread2
quitting thread2

You might also like