• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hi rahul, please help me!!!!!

 
prasanth chiru
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have coded the following example to check for interrupt().
Can you please explain the output, why it is coming like that.

class Thread1 extends Thread
{
public void run()
{
try{
System.out.println("Inside run:1");
sleep(10000);
System.out.println("Inside run:2");
}
catch(InterruptedException e)
{
System.out.println("Inside interrupted exception");
}
System.out.println("after catch");
}
}
class Thread4 extends Thread
{
public void run()
{
System.out.println("Inside thread4 run");

}
}
class Thread2
{
public static void main(String args[])
{
Thread1 x = new Thread1();
x.start();
Thread4 y = new Thread4();
x.interrupt();
y.start();
System.out.println("Inside main method");

}
}
If I place the x.interrupt() statement after y.start(), what will happen. please explain me. I am confused.
Thanks.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code works as predicted so what exactly is the problem you are facing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic