个人可以备案网站的内容,石家庄货运做网站公司,做销售在哪些网站注册好,苏州做网站公Java ThreadGroup setDaemon()方法java.lang.ThreadGroup.setDaemon() 方法改变该线程组的守护进程的状态。当其最后一个线程被停止或它的最后一个线程组被销毁守护线程组会自动销毁。1 语法public final void setDaemon(boolean daemon)2 参数daemon #xff1a; 如果为true 如果为true这标志着该线程组作为守护线程组;否则标志着该线程组为正常。3 返回值此方法不返回任何值。4 示例package com.yiidian;/*** 一点教程网 http://www.yiidian.com*//*** Java ThreadGroup setDaemon()方法*/import java.lang.*;public class ThreadGroupDemo implements Runnable{public static void main(String[] args) {ThreadGroupDemo tg new ThreadGroupDemo();tg.func();}public void func() {try {// create a parent ThreadGroupThreadGroup pGroup new ThreadGroup(Parent ThreadGroup);// daemon status is set to truepGroup.setDaemon(true);// create a child ThreadGroup for parent ThreadGroupThreadGroup cGroup new ThreadGroup(pGroup, Child ThreadGroup);// daemon status is set to truecGroup.setDaemon(true);// create a threadThread t1 new Thread(pGroup, this);System.out.println(Starting t1.getName() ...);t1.start();// create another threadThread t2 new Thread(cGroup, this);System.out.println(Starting t2.getName() ...);t2.start();// returns true if this thread group is a daemon thread groupSystem.out.println(Is pGroup.getName() a daemonThreadGroup? pGroup.isDaemon());System.out.println(Is cGroup.getName() a daemonThreadGroup? cGroup.isDaemon());// block until the other threads finisht1.join();t2.join();}catch (InterruptedException ex) {System.out.println(ex.toString());}}// implements run()public void run() {for(int i 0;i 1000;i) {i;}System.out.println(Thread.currentThread().getName() finished executing.);}}输出结果为Starting Thread-0...Starting Thread-1...Is Parent ThreadGroup a daemonThreadGroup? trueIs Child ThreadGroup a daemonThreadGroup? trueThread-0 finished executing.Thread-1 finished executing.