join()作用,并行加入线程,别加入线程处于阻塞状态,理解成插队
因为中途加入,要抛打断异常
package thread;
public class TestJoin implements Runnable{
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("vip线程执行"+i);
}
}
public static void main(String[] args) throws InterruptedException {
TestJoin testJoin = new TestJoin();
Thread thread = new Thread(testJoin);
thread.start();
for (int i = 0; i < 10; i++) {
System.out.println("main"+i);
if (i==5){
thread.join();
}
}
}
}