新线程的启动方式

新线程的启动方式

package ch1.base.safeend;

//新启动线程的方式
public class NewThread {

    //extends
    private static class UserThread extends Thread{
        public void run(){
            super.run();
            System.out.println("i am extends Thread");
        }
    }

    //实现runnable接口
    private static class UserRunnable implements Runnable{
        public void run(){
            System.out.println("i am implements runnable");
        }
    }

    public static void main(String[] args) throws Exception {
        UserThread userThread = new UserThread();
        userThread.start();
//        userThread.start();


        UserRunnable userRunnable = new UserRunnable();
        new Thread(userRunnable).start();
    }
}

你可能感兴趣的:(新线程的启动方式)