java线程 join

来源:互联网 发布:ug编程没刀库的刀具号 编辑:程序博客网 时间:2024/06/06 09:04
package thread.thread3;


public class JoinTest extends Thread {
    private static Integer num = 0;


    public static void main(String[] args) throws InterruptedException {
        JoinTest thread = new JoinTest();
        thread.start();
        //join 等当前线程执行完后才开始执行其他线程
        thread.join();
        System.out.println("num" + num);
    }


    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            System.out.println(num++);
        }
    }
}
0 0
原创粉丝点击