zoukankan      html  css  js  c++  java
  • 多线程依赖打印(join)

    package japan.example.test;
    
    public class ThreadJoinTest {
    
        public static void main(String[] args) throws InterruptedException {
    
            new ThreadJoinTest().test();
        }
    
        public void test() throws InterruptedException {
    
            Thread[] tt = new Thread[100];
            for (int i = 0; i < tt.length; i++) {
                tt[i] = new Thread(new ThreadJoin(i == 0 ? null : tt[i - 1]));
            }
    
            for (int i = 0; i < tt.length; i++) {
                tt[i].start();
            }
    
            Thread.sleep(1000);
        }
    
    }
    
    class ThreadJoin implements Runnable {
    
        Thread t;
    
        ThreadJoin(Thread t) {
            this.t = t;
        }
    
        @Override
        public void run() {
            try {
                if (t != null) {
                    t.join();
                }
                String name = Thread.currentThread().getName();
                System.err.println("name|{}" + name);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    
        }
    }
  • 相关阅读:
    相关正则的一些知识
    数组中的方法
    封装ajax
    swiper结合ajax的轮播图
    事件
    原型、原型链
    HTML 常用标签
    HTML基础了解
    JSON 与 XML基本了解
    JavaScript(js)
  • 原文地址:https://www.cnblogs.com/jpit/p/8444362.html
Copyright © 2011-2022 走看看