zoukankan      html  css  js  c++  java
  • 线程join

     
    class ThreadB extends Thread
    {
        private String ID="0";
        private int time=0;
        public ThreadB(String ID,int time)
        {
            this.ID=ID;
            this.time=time;
        }
        public void run()
        {
            System.out.println("线程A"+ID+"开始了");
            int i=1;
            try
            {
                while(i<=time)
                {
                    System.out.println("线程A"+ID+"运行的 次数"+ i++);
                    Thread.sleep(200);
                }
            } catch (Exception e)
            {
                // TODO: handle exception
                e.printStackTrace();
            }
            System.out.println("线程A"+ID+"结束");
        }
     
    }
     
     
    public class JoinThrea
    {
        public static void main(String []args)
        {
            Thread thread1=new ThreadB("1",3);
            Thread thread2=new ThreadB("2",10);
            Thread thread3=new ThreadB("3",5);
            Thread thread4=new ThreadB("4",15);
            thread1.start();
     
            try
            {
                thread1.join();//只有当此线程结束 后面的线程才会开始
            } catch (Exception e)
            {
                // TODO: handle exception
            }
            thread2.start();
            thread3.start();
            thread4.start();
            try
            {
                thread1.join();
                thread2.join();
                thread3.join();
                thread4.join();
            } catch (InterruptedException  e)
            {
                // TODO: handle exception
                e.printStackTrace();
            }
     
            System.out.println("全部结束");//只有当以上所有线程结束后才会 运行
        }
    }
    梦里不知身是客,一晌贪欢。
  • 相关阅读:
    JAVA BigDecimal 小数点处理
    对 Element UI table中数据进行二次处理
    Kettle-User Defined Java Class使用-大写转换
    多线程-同步函数
    多线程-银行分批存款
    多线程-并发卖票
    多线程-控制两个线程交替打印
    ztree-可拖拽可编辑的树
    ztree-编辑节点(树节点添加,删除,修改)
    ztree-拖拽(排序树)
  • 原文地址:https://www.cnblogs.com/dccmmtop/p/5710170.html
Copyright © 2011-2022 走看看