ThreadGroup
类的isDaemon()
方法测试此线程组是否为守护程序线程组。
语法
public final boolean isDaemon()
返回
如果此线程组是守护程序线程组,则此方法返回true
。 否则,它将返回false
。
示例
class NewThread extends Thread
{
NewThread(String threadname, ThreadGroup tg)
{
super(tg, threadname);
}
public void run()
{
for(int i = 0;i < 10;i++)
{
i++;
}
System.out.println(Thread.currentThread().getName() + " finished executing");
}
}
public class ThreadGroupIsDaemonExp
{
public static void main(String arg[]) throws InterruptedException,
SecurityException, Exception
{
// creating a threadGroup
ThreadGroup tg = new ThreadGroup("Parent thread");
// creating a thread
NewThread t1 = new NewThread("Thread-1", tg);
t1.start();
// returns false if this thread group is not a daemon thread group
System.out.println("Is " + tg.getName() + " a daemon threadGroup? " + tg.isDaemon());
}
}
执行上面示例代码,得到以下结果:
Is Parent thread a daemon threadGroup? false
Thread-1 finished executing