通过实现Runnable接口的方式创建线程

 1 package day01;
 2 
 3 /*
 4  * 通过自定义类实现Runnable接口,重写run方法,调用start方法启动对象
 5  * */
 6 public class ThreadCreate implements Runnable {
 7     @Override
 8     public void run() {
 9         //run方法线程体
10         for (int i = 1; i <= 10; i++) {
11             System.out.println("run方法线程-》" + i);
12         }
13     }
14 
15     public static void main(String[] args) {
16         //创建一个线程对象
17         ThreadCreate thread1 = new ThreadCreate();
18         //开启线程对象
19         new Thread(thread1).start();
20         //main主线程
21         for (int i = 1; i <= 1000; i++) {
22             System.out.println("主线程--》" + i);
23         }
24     }
25 }
执行结果:

欢迎批评指正,提出问题,谢谢!
原文地址:https://www.cnblogs.com/xxeleanor/p/15203124.html