1. 程式人生 > >java多線程快速入門(三)

java多線程快速入門(三)

err out clas pri pub ride style 通過 ()

//通過實現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("主函數結束"); } }

java多線程快速入門(三)