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();