A thread during a possession cpu resources, other resources can make calls join () and this thread joint, such as:
B.join ();
A joint during operation when the B, A thread execution is interrupted immediately, wait until he finished joint thread B, A thread re-queued for CPU resources.
Code
package 合并线程join;
public class JOIN {
public static void main(String[] args) {
Thread t =new Thread(()->{ //lambde模式
for (int i = 1; i <= 5; i++) {
System.out.println(Thread.currentThread().getName()+i);
}
},"小美") ;
t.start();
for (int i = 1; i <=5; i++) {
System.out.println(i);
if(i%3==0) {
try {
t.join();//插队
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//
}
}
}
}