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 {
//w  ww .j  a v a  2 s .co 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();
  }
}




















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