public class IsInterrupted extends Thread {
@Override
public void run() {
//change the status of interrupted from true to false
//only if thread is interrupted
//interrupted() is a static method
//can be invoked using thread.interrupted()
System.out.println(Thread.interrupted()); //true->false
//does not change the interrupted status
//only gives the status
//not a static method
//have to be invoked using currentThread()
System.out.println(Thread.currentThread().isInterrupted());
try {
for (int i = 1; i <= 5; i++) {
System.out.println(i);
Thread.sleep(1000);
}
} catch (Exception e) {
System.out.println("Thread interrupted : " + e);
}
}
public static void main(String[] args) {
IsInterrupted ti = new IsInterrupted();
ti.start();
// ti.interrupt();
}
}