package com.freeflying.thread.join;
/**
* join方法的使用
* @ClassName: JoinUse
* @Description:
* @author freeflying
* @date 2018年7月26日
*/
public class JoinUse {
public static void main(String[] args) {
try {
JoinUseEx joinUseEx=new JoinUseEx();
joinUseEx.start();
joinUseEx.join();
System.out.println("joinUseEx execute finally,then i execute!!");
}catch (Exception e) {
// TODO: handle exception
}
}
}
class JoinUseEx extends Thread{
@Override
public void run() {
try {
int second=(int)(Math.random()*10000);
System.out.println("i execute!! sleep :"+second);
Thread.sleep(second);
} catch (Exception e) {
// TODO: handle exception
}
}
}
join方法会让当前线程阻塞并等待正在run的线程执行完后再执行当前线程