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); } } }
原文:https://www.cnblogs.com/sadfoo/p/12961985.html