join方法

join():当前线程等待子线程终止

class MyThread implements Runnable {
    public void run() {
        int i = 0;
        while(i < 100) {
            System.out.println(Thread.currentThread() + " a = " + i);
            i++;
            Thread.yield();
        }
    }
}
public class Demo1 {

    public static void main(String[] args) throws Exception {
        Thread t1 = new Thread(new MyThread(),"t1");
        t1.start();
        t1.join(1);
        System.out.println(Thread.currentThread()+ "tttttttttttttt");
    }
posted @ 2020-03-15 22:21  卑微芒果  Views(138)  Comments(0Edit  收藏  举报