- Join()方法是让一个线程等待另一个线程的完成
![这里写图片描述](https://img-blog.csdn.net/20171223124920844?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzkwNDY3Mjc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
下面看个例子:
package project11;
public class TestJoin extends Thread {
public void run() {
for(int i= 1;i<=10;i++)//线程循环10次输出
{
System.out.println(Thread.currentThread().getName()+"第"+i+"次运行");
}
System.out.println(Thread.currentThread().getName()+"运行结束");
}
public static void main(String [] args) { //main函数的主线程开始运行
System.err.println("主线程开始运行");
TestJoin tj = new TestJoin(); //创建线程类
tj.setName("线程1"); //给线程起名字
try {
long start = System.nanoTime();
tj.start();
tj.join(); //等待tj线程运行结束
long end = System.nanoTime();
System.out.println("耗时&