美文网首页
【Java】【Thread多线程】线程组

【Java】【Thread多线程】线程组

作者: JerichoPH | 来源:发表于2017-04-08 08:51 被阅读19次

    线程组

    public class Demo {
        public static void main(String[] args) throws IOException, InterruptedException {
            ThreadGroup tg = new ThreadGroup("新线程组");
            MyRunnable mr = new MyRunnable();
            
            Thread t1 = new Thread(tg, mr, "张三");
            Thread t2 = new Thread(tg, mr, "李四");
            
            System.out.println(t1.getThreadGroup().getName());
            System.out.println(t2.getThreadGroup().getName());
        }
    }
    
    class MyRunnable implements Runnable {
    
        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + "......" + i);
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:【Java】【Thread多线程】线程组

          本文链接:https://www.haomeiwen.com/subject/feflattx.html