Thread interrupt check : Thread Attributes « Threads « Java






Thread interrupt check

Thread interrupt check
 
public class InterruptCheck extends Object {
  public static void main(String[] args) {
    Thread t = Thread.currentThread();
    System.out.println("A: t.isInterrupted()=" + t.isInterrupted());
    t.interrupt();
    System.out.println("B: t.isInterrupted()=" + t.isInterrupted());
    System.out.println("C: t.isInterrupted()=" + t.isInterrupted());

    try {
      Thread.sleep(2000);
      System.out.println("NOT interrupted");
    } catch (InterruptedException x) {
      System.out.println("Interrupted");
    }

    System.out.println("D: t.isInterrupted()=" + t.isInterrupted());
  }
}

           
         
  








Related examples in the same category

1.Thread nameThread name
2.Get Thread nameGet Thread name
3.Thread PriorityThread Priority
4.Set Thread PrioritySet Thread Priority
5.Thread Interrupt when calculating PiThread Interrupt when calculating Pi
6.Thread pending and interruptThread pending and interrupt
7.Thread interrupt resetThread interrupt reset
8.Thread priority informationThread priority information
9.Thread general interruptThread general interrupt
10.Thread IDThread ID
11.ThreadGroup EnumerateThreadGroup Enumerate
12.Utilities to manage thread ids