当调用线程Join()时,调用Join()方法的线程会强制先执行完, 想象为Vip插队,必须等调用Join()的线程执行完后其他线程才能执行 /** * @Author Chengzhi * @Date 2021/4/19 9:02 * @Version 1.0 * * 测试Join * 插队 */ public class TestJoin implements Runnable{ @Override public void run() { for (int i = 0; i < 100; 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 < 1000; i++) { if (i == 200) { thread.join(); } System.out.println("main方法下的输出" + i); } } }
COMMENTS | NOTHING