下面是Java代码实现:

public class MyThread extends Thread {
    private String name;

    public MyThread(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println(name);
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        MyThread thread1 = new MyThread("Thread1");
        MyThread thread2 = new MyThread("Thread2");

        thread1.start();
        thread2.start();
    }
}
``

原文地址: http://www.cveoy.top/t/topic/gIou 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录