线程组:让现在在一个组内,对组操作就是对组内的所有线程操作

public class MyRunnable implements Runnable {

    @Override
    public void run() {
        for (int x = 0; x < 5; x++) {
            System.out.println(Thread.currentThread().getName() + ":" + x);
        }
    }

}
    public static void main(String[] args) {
        MyRunnable my=new MyRunnable();
        //创建线程组并命名,默认命名main
        ThreadGroup tg=new ThreadGroup("逗逼线程组");
        //设置线程的线程组
        Thread t1=new Thread(tg,my,"线程1");
        Thread t2=new Thread(tg,my,"线程1");
        System.out.println(t1.getThreadGroup().getName());
        System.out.println(t2.getThreadGroup().getName());
        tg.setDaemon(true);
    }
posted on 2017-04-07 01:20  2637282556  阅读(127)  评论(0编辑  收藏  举报