Java Thread.isInterrupted()

Syntax

Thread.isInterrupted() has the following syntax.

public boolean isInterrupted()

Example

In the following code shows how to use Thread.isInterrupted() method.


//from ww  w .  j  a v a2  s.  c  om


class ThreadDemo implements Runnable {
  public void run() {
    try {
      while (true) {
        Thread.sleep(1000);
      }
    } catch (InterruptedException e) {
      System.out.println(e.toString());
    }
  }

}

public class Main {

  public static void main(String args[]) {

    Thread t = new Thread(new ThreadDemo());
    System.out.println("Executing " + t.getName());
    t.start();

    if (!t.isInterrupted()) {
      t.interrupt();
    }
    try {
      t.join();
    } catch (InterruptedException e) {
    }
  }

}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable