API创建线程的两种方式

class MyThread extends Thread{
    public  MyThread(){
        super();
    }

    @Override
    public void run() {
        for(int i=0;i<100;i++){
            System.out.println("子线程:"+i);
        }
    }
}


public class TestThread {
    public static void main(String[] args) {
        MyThread mt=new MyThread();
        mt.start();
    }
}

class MyThread implements Runnable{
    public  MyThread(){
        super();
    }

    @Override
    public void run() {
        for(int i=0;i<100;i++){
            System.out.println("子线程:"+i);
        }
    }
}

public class TestThread {
    public static void main(String[] args) {
        MyThread mt=new MyThread();
        Thread t1=new Thread(mt);
        t1.start();
    }
}

猜你喜欢

转载自blog.csdn.net/qq_41048982/article/details/109305519