目录

boolean isDaemon()

描述 (Description)

java.lang.Thread.isDaemon()方法测试此线程是否为守护程序线程。

声明 (Declaration)

以下是java.lang.Thread.isDaemon()方法的声明

public final boolean isDaemon()

参数 (Parameters)

NA

返回值 (Return Value)

如果此线程是守护程序线程,则此方法返回true; 否则是假的。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.Thread.isDaemon()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018