Java.lang.Thread.isDaemon() Method



Description

The java.lang.Thread.isDaemon() method tests if this thread is a daemon thread.

Declaration

Following is the declaration for java.lang.Thread.isDaemon() method

public final boolean isDaemon()

Parameters

NA

Return Value

This method returns true if this thread is a daemon thread; false otherwise.

Exception

NA

Example

The following example shows the usage of java.lang.Thread.isDaemon() method.

package com.tutorialspoint;

import java.lang.*;

class adminThread extends Thread {

   adminThread() {
      setDaemon(true);
   }

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

public class ThreadDemo {

   public static void main(String[] args) throws Exception {
    
      Thread thread = new adminThread();
      System.out.println("thread = " + thread.currentThread());
      thread.setDaemon(true);
   
      // this will call run() method
      thread.start();
   }
} 

Let us compile and run the above program, this will produce the following result −

thread = Thread[main,5,main]
isDaemon = true
java_lang_thread.htm
Advertisements