[小练习] 多线程的两种实现方式

public class Test {
    public static void main(String[] args) {
        Thread1 thread1 = new Thread1();
        Runnable r = new Thread2();
        Thread thread2 = new Thread(r);
        thread1.start();
        thread2.start();
        for (int i = 0; i < 100; i++) {
            System.out.println("Main Thread =>This is " + i);
        }
    }
}

class Thread1 extends Thread {
    @Override
    public void run() {
        // TODO Auto-generated method stub
        super.run();
        for (int i = 0; i < 100; i++) {
            System.out.println("Thread 1 =>This is " + i);
        }
    }
}

class Thread2 implements Runnable {
    @Override
    public void run() {
        // TODO Auto-generated method stub
        for (int i = 0; i < 100; i++) {
            System.out.println("Thread 2 =>This is " + i);
        }
    }
}

你可能感兴趣的:([小练习] 多线程的两种实现方式)