Thread class test join () method

public class TestJoin{
    
    public static void main(String[] args){
        Thread t = new Thread(new MyRunner());
        t.start();
        try{
                t.join();
            } catch(InterruptedException e){
                e.printStackTrace();
            }
            for(int i=0;i<10;i++){
            System.out.println("Main:" + i);
        }
    }
    
}

class MyRunner implements Runnable{
    
    public void run(){
        for(int i=0;i<10;i++){
            System.out.println("MyRunner:" + i);
            try{
                Thread.sleep(1000);
            } catch(InterruptedException e){
                e.printStackTrace();
            }
        }
    }
    
}

 

Guess you like

Origin www.cnblogs.com/yxfyg/p/12418531.html