Java中多线程的声明方式

 //第一种(直接创建)
        Thread thread = new Thread();
        thread.start();
        System.out.println("第一种Thread写法");

        //第二种(以之类的形式创建)
        Thread threadExtread = new ThreadExtread();
        threadExtread.start(); 
        //第一种和第二种其实相同
        
        //第三种(组合形式创建)
        Thread threadThree = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("第三种Thread写法");
            }
        });
        threadThree.start();

public class ThreadExtread extends Thread {

    @Override
    public void run() {
        System.out.println("第二种Thread写法");     
    }
}

你可能感兴趣的:(Java中多线程的声明方式)