Java 多线程问题


public class  Demo implements Runnable{

    public static void main(String [] args){
            Demo deo = new Demo();
            deo.run();
            System.out.println("main.....");
    }

    @Override
    public void run() {
        try{
            Thread.sleep(1000);
            System.out.println("try......");
        }catch(Exception e){
            System.out.println(e);
        }finally{
            System.out.println("finally....");
        }
    }
}

 

直接用run方法来启动线程是不对的,用run方法来启动只是一个函数调用,所以会先执行run函数内容。

真正启动线程的方法应该是:new Thread(Runnable obj).start();

猜你喜欢

转载自blog.csdn.net/qq_36290948/article/details/88086600