zoukankan      html  css  js  c++  java
  • 线程中join用法

    1 join()  当前线程中出现 thread1.join()  会先执行完thread1 然后再执行当前线程

    public static void main(String[] args) {
            final Thread threadN = new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println("产品经理正在规划新需求...");
                }
            });
    
            final Thread thread2 = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        thread1.join();
                        System.out.println("开发人员开发新需求功能");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
    
            final Thread thread3 = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        thread2.join();
                        System.out.println("测试人员测试新功能");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
    
            try {
                System.out.println("产品经理来上班了");
                System.out.println("测试人员来上班了");
                System.out.println("开发人员来上班了");
                thread1.start();
                //在父进程调用子进程的join()方法后,父进程需要等待子进程运行完再继续运行。
                System.out.println("开发人员和测试人员休息会...");
                thread1.join();
                System.out.println("产品经理新需求规划完成!");
                thread2.start();
                System.out.println("测试人员休息会...");
                thread2.join();
                thread3.start();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
  • 相关阅读:
    复制某文件夹及其子文件夹中的一定大小的文件
    一个简单的查询脚本
    写一个交互的脚本
    nginx+php5.6.12+discuz
    curl 错误
    python 交互界面tab补全
    uwsgi.xml
    supervisorctl
    认识nginx配置文件
    nginx+uwsgi+django 配置3
  • 原文地址:https://www.cnblogs.com/spring20190213dream/p/10601567.html
Copyright © 2011-2022 走看看