JavaSE系列代码34:线程中join()方法的使用

When a method is called, if the method has parameters, the parameters must be instantiated, that is, the parameter variables must have specific values. In Java, all the parameters of a method are value passing, that is, the value of the parameter variable in a method is a copy of the value specified by the caller. If you pass an int value to the int parameter X of the method, the value obtained by the parameter x is a copy of the passed value. Method if you change the value of the parameter, it does not affect the value of the variable “pass value” to the parameter.

public class Javase_34
{
  public static void main(String[] args)
  {
    myThread you=new myThread("你");
    myThread she=new myThread("她");
    you.start();   //激活you线程
    try{
      you.join();  //限制you线程结束后才能往下执行
    }
    catch(InterruptedException e) {}
    she.start();
    try{
      she.join();  //限制she线程结束后才能往下执行
    }
    catch(InterruptedException e) {}
    System.out.println("主方法main()运行结束!");
  }
}
发布了52 篇原创文章 · 获赞 162 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/blog_programb/article/details/105393440