package com.chengguo.線程; /** * 建立線程方式2:實現runnable接口,從新run方法,執行線程須要丟入runnable接口實現類,調用start */ public class Demo_20200509001_Thread2 implements Runnable { @Override public void run() { //run方法線程體 for (int i = 0; i < 20; i++) { System.out.println("我是run方法線程體……" + i); } } public static void main(String[] args) { //建立runnable接口的實現類對象 Demo_20200509001_Thread2 dt = new Demo_20200509001_Thread2(); //建立一個線程對象,經過線程對象來開啓線程 Thread thread = new Thread(dt); //調用start方法開啓線程 thread.start(); // new Thread(dt).start(); for (int i = 0; i < 1000; i++) { System.out.println("我在學習多線程……" + i); } } }