Sunday, January 19, 2014

Program of interrupting a thread that stops working

class InterRupt1 extends Thread
{
public void run()
{
try
{
Thread.sleep(1000);
System.out.println("Work");
}
catch(InterruptedException e)
{
throw new RuntimeException("Thread interrupted..." + e);
}
}
public static void main(String surat[])
{
InterRupt1 t1=new InterRupt1();
t1.start();
try
{
t1.interrupt();
}
catch(Exception e)
{
System.out.println("Exception handled "+e);
}
}
}

Output:

No comments:

Post a Comment