Thread with Synchronization

public class ABC1 extends Thread
{
Thread t1,t2,t3;

public ABC1()
{
t1=new Thread(this,"First");
t2=new Thread(this,"Second");
t3=new Thread(this,"Third");

t1.start();
t2.start();
t3.start();

t3.setPriority(10);
t2.setPriority(1);//default priority
t1.setPriority(7);
}
public void run()
{
synchronized(this)
{
for(int i=1;i<=4;i++)
{
System.out.println(Thread.currentThread().getName()+" i = "+i);
try
{
yield();
}
catch(Exception e)
{
System.out.println("Message : "+e);
}
}
}
}
public static void main(String arg[])
{
ABC1 obj=new ABC1();
}
}

Comments

Popular Posts