Thread pending and interrupt : Thread Attributes « Threads « Java






Thread pending and interrupt

Thread pending and interrupt
 

public class PendingInterrupt extends Object {
  public static void main(String[] args) {
    Thread.currentThread().interrupt();

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

    System.out.println("elapsedTime="
        + (System.currentTimeMillis() - startTime));
  }
}
           
         
  








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 interrupt resetThread interrupt reset
7.Thread interrupt checkThread interrupt check
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