Thread join 证明

public class ThreadTest {
    public static void main(String[] args) {

        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                for (int j = 0; j < 5000; j++) {
                    System.out.println(Thread.currentThread().getName() + "线程打印" + j);
                }
            }, String.valueOf(i));
            thread.start();
            try {
                thread.join();                    //案例1 证明join让多线程同步执行
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}

posted @ 2020-08-04 22:23  z_先生  阅读(51)  评论(0编辑  收藏  举报