Start,Run在执行上的区别

StartAndRun在执行上的区别

package ch1.base.safeend;

//StartAndRun在执行上的区别
public class SleepAndRun {
    public static class ThreadRun extends Thread{
        public void run(){
            int i=9;
            while(i>0){
                try{
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }

                System.out.println("I am "+Thread.currentThread().getName()+" and now the i="+i--);
            }
        }
    }

    public static void main(String[] args) {
        ThreadRun threadRun = new ThreadRun();
        threadRun.setName("treadRun");
        threadRun.start();
    }
}

你可能感兴趣的:(Start,Run在执行上的区别)