• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Girish Nagaraj
Ranch Hand
Posts: 153
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A extends Thread {

public void run() {

try {

Thread.sleep(2000);
} catch (InterruptedException ie) {

System.out.println("Thread Interrupted");
}

System.out.println("\n" + interrupted());
System.out.println(interrupted());
}
}

class X {

public static void main(String[] args) {

A t = new A();
t.start();
t.interrupt();
}
}

Output
------
Thread Interrupted
false
false // Why false here

interrupted() resets interrupt flag right?


Thanks in Advance.
 
wise owen
Ranch Hand
Posts: 2023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each Thread has an associated boolean interruption status. Invoking t.interrupt for some Thread t sets t's interruption status to true, unless Thread t is engaged in Object.wait, Thread.sleep, or Thread.join; in this case interrupt causes these actions (in t) to throw InterruptedException, but t's interruption status is set to false.
 
Girish Nagaraj
Ranch Hand
Posts: 153
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks wise
 
Amirr Rafique
Ranch Hand
Posts: 324
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi wise
can you plz explain bit more

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic