zoukankan      html  css  js  c++  java
  • Java线程中的join使用实例

    JDK中解释为 Waits for this thread to die. 等待本线程结束后,下一个线程才可以运行。

    实例要求:

    现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行

    实现代码:

    package com.st.lesson02;
    
    public class Test01 {
        //1.现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行
        public static void main(String[] args) throws InterruptedException {
            Thread th1 = new Thread01();
            Thread th2 = new Thread02();
            Thread th3 = new Thread03();
            th1.start();
            th1.join();
            System.out.println("Thread01运行结束。。。");
            th2.start();
            th2.join();
            System.out.println("Thread02运行结束。。。");
            th3.start();
            th3.join();
            System.out.println("Thread03运行结束。。。");
            System.out.println("------主函数-------");
        }
    }
    class Thread01 extends Thread{
        
        public void run() {
            System.out.println("Thread01...running...");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    class Thread02 extends Thread{
        public void run() {
            System.out.println("Thread02...running...");
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            
        }
    }
    class Thread03 extends Thread{
        public void run() {
            System.out.println("Thread03...running...");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            
        }
    }

    运行效果图:

  • 相关阅读:
    移动采编app
    分布式自动化测试
    appium --log-timestamp > appium.log
    处理安卓的弹窗
    Sublime text3修改tab键为缩进为四个空格
    安卓自动化测试——rf
    敏捷软件开发
    photoshop怎么旋转图片
    thinkPHP5.0模型实现软删除
    thinkPHP5.0数据查询表达式生成技巧
  • 原文地址:https://www.cnblogs.com/xiaotao726/p/6493099.html
Copyright © 2011-2022 走看看