Java Data Type Tutorial - Java Thread.isDaemon()








Syntax

Thread.isDaemon() has the following syntax.

public final boolean isDaemon()

Example

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

class MyThread extends Thread {
/*from   w w  w  .  j a  v a  2s  . c  o m*/
  MyThread() {
    setDaemon(true);
  }

  public void run() {
    boolean d = isDaemon();
    System.out.println("isDaemon = " + d);
  }
}

public class Main {

  public static void main(String[] args) throws Exception {

    Thread thread = new MyThread();
    System.out.println("thread = " + thread.currentThread());
    thread.setDaemon(true);

    // this will call run() method
    thread.start();
  }
}

The code above generates the following result.