线程

ThreadLocale的使用. 用完变量需要remove
Join 方法的使用,t2 会等待 t1完成, 在开始执行

  public static void main(String[] args){
        Thread t1 = new Thread(new JoinThread());
        Thread t2 = new Thread(()->{
            try {
                t1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for (int i = 0; i <1000 ; i++) {
                System.out.println(Thread.currentThread().getName() + " " + i);
            }
        });
        t1.start();
        t2.start();

}

@Override
public void run() {
    for (int i = 0; i <1000 ; i++) {
        System.out.println(Thread.currentThread().getName() + " " + i);
    }

}

你可能感兴趣的:(线程)