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("全部结束");//只有当以上所有线程结束后才会 运行
        }
    }
    梦里不知身是客,一晌贪欢。
  • 相关阅读:
    启发式搜索学习~~
    bzoj1032
    bzoj1037
    bzoj1029
    codevs1081 线段树练习 2
    bzoj1006
    bzoj1003
    Codeforces 607B Zuma
    20155326《网络对抗》网络欺诈技术防范
    20155326刘美岑 Exp6 信息收集与漏洞扫描
  • 原文地址:https://www.cnblogs.com/dccmmtop/p/5710170.html
Copyright © 2011-2022 走看看