Sunday, January 19, 2014

interrupt() method example..

class Thread19 extends Thread
{
Thread19(String s)
{
super(s);
}
public void run()
{
System.out.println(getName());
try
{
Thread.sleep(500);
}
catch(Exception e)
{
System.out.println("Interrupted Forcly " + e);
}
System.out.println(getName() + " Dead ");
}
}
class Thread20 extends Thread
{
Thread19 t;
Thread20(String s, Thread19 t)
{
super(s);
this.t=t;
}
public void run()
{
System.out.println(getName());
t.interrupt();
try
{
Thread.sleep(500);
}
catch(Exception e){}
System.out.println(getName() + " Dead ");
}
}
class InterRupt5
{
public static void main(String surat[])
{
Thread19 t1=new Thread19("Thread1");
t1.setPriority(10);

Thread20 t2=new Thread20("Thread2",t1);
t2.setPriority(10);

t1.start();
t2.start();
}
}

Output:

No comments:

Post a Comment