• java笔记线程方式1等待终止


     public final void join():等待该线程终止

    public class ThreadJoinDemo {
        public static void main(String[] args) {
            ThreadJoin tj1 = new ThreadJoin();
            ThreadJoin tj2 = new ThreadJoin();
            ThreadJoin tj3 = new ThreadJoin();
    
            tj1.setName("李渊");
            tj2.setName("李世民");
            tj3.setName("李元霸");
    
            tj1.start();//liyuan走完了才继续下面
            try {
                tj1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            
            tj2.start();
            tj3.start();
        }
    }
    public class ThreadJoin extends Thread {
        @Override
        public void run() {
            for (int x = 0; x < 100; x++) {
                System.out.println(getName() + ":" + x);
            }
        }
    }
  • 相关阅读:
    DAY 223 GIT
    swooleHTTP
    swooleWebSocket
    swooleUDP
    swoole异步MySql
    swooleTCP
    谈谈继承的局限性
    也谈过程决定质量
    谁该为参数负责
    使用function改进设计
  • 原文地址:https://www.cnblogs.com/lanjianhappy/p/6383951.html
Copyright © 2020-2023  润新知