java多线程快速入门(三)

通过实现Runnable接口实现多线程

package com.cppdy;


//通过实现Runnable接口实现多线程
class MyThread1 implements Runnable{

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

public class ThreadDemo1 {

    public static void main(String[] args) {
        System.out.println("主函数启动");
        MyThread1 mt=new MyThread1();
        Thread thread = new Thread(mt);
        thread.start();
        for (int i = 0; i < 30; i++) {
            System.out.println("主函数打印:"+i);
        }
        System.out.println("主函数结束");
    }

}
原文地址:https://www.cnblogs.com/jiefu/p/10013916.html