
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java Thread isDaemon() Method
Description
The Java 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: Checking a Daemon Thread being false
The following example shows the usage of Java Thread isDaemon() method. In this program, we've created a thread class AdminThread by extending Thread class. In constructor, we've set the thread status being Daemon as false using setDaemon() method. In run() method, we're printing the status of the thread being Daemon or not using isDaemon(). In main() method, a thread of AdminThread is created and Daemon is set false using setDaemon() method and start() method is called to run the thread.
package com.tutorialspoint; class AdminThread extends Thread { AdminThread() { setDaemon(false); } public void run() { boolean d = isDaemon(); System.out.println("daemon = " + d); } } public class ThreadDemo { public static void main(String[] args) throws Exception { Thread thread = new AdminThread(); System.out.println("thread = " + thread.currentThread()); thread.setDaemon(false); // this will call run() method thread.start(); } }
Output
Let us compile and run the above program, this will produce the following result −
thread = Thread[main,5,main] daemon = false
Example: Checking a Daemon Thread being false
The following example shows the usage of Java Thread isDaemon() method. In this program, we've created a thread class AdminThread by extending Thread class. In constructor, we've set the thread status being Daemon as false using setDaemon() method. In run() method, we're printing the status of the thread being Daemon or not using isDaemon() method. In main() method, a thread of AdminThread is created and Daemon is set True using setDaemon() method and start() method is called to run the thread.
package com.tutorialspoint; class AdminThread extends Thread { AdminThread() { setDaemon(false); } public void run() { boolean d = isDaemon(); System.out.println("daemon = " + 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(); } }
Output
Let us compile and run the above program, this will produce the following result −
thread = Thread[main,5,main]