java.lang.Thread.isDaemon()%uA0方法测试该线程是否为守护线程。
声明
以下是java.lang.Thread.isDaemon()方法的声明
public final boolean isDaemon()
参数
-
NA
返回值
如果该线程是守护线程此方法返回true否则为false。
异常
-
NA
例子
下面的例子显示java.lang.Thread.isDaemon()方法的使用。
package com.yiibai 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