Java.lang.Thread.isDaemon() 方法
描述
java.lang.Thread.isDaemon() 方法测试这个线程是否是一个守护线程。
声明
以下是 java.lang.Thread.isDaemon() 方法的声明。
public final boolean isDaemon()
参数
NA
返回值
如果此线程是守护线程,则此方法返回 true; 否则为 false 。
异常
NA
示例
下面的例子展示了 java.lang.Thread.isDaemon() 方法的使用。
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();
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
thread = Thread[main,5,main] isDaemon = true

