1、继承Thread类,新建一个当前类对象,并且运行其start()方法

 1 package com.xiaostudy.thread;
 2 
 3 /**
 4  * @desc 第一种开启线程的方式
 5  * @author xiaostudy
 6  *
 7  */
 8 public class Demo1_Thread extends Thread {
 9 
10     public void run() {
11         for (int i = 0; i < 10; i++) {
12             System.out.println(i + " run()...");
13         }
14     }
15 
16     public static void main(String[] args) {
17         Demo1_Thread demo = new Demo1_Thread();
18         demo.start();
19         for (int i = 0; i < 10; i++) {
20             System.out.println(i + " main()...");
21         }
22     }
23 
24 }
Demo1_Thread.java

相关文章:

  • 2021-11-24
  • 2021-11-23
  • 2021-07-20
  • 2021-12-07
  • 2021-11-23
  • 2021-11-23
  • 2021-11-27
  • 2021-09-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2021-11-26
  • 2021-08-12
  • 2021-07-20
  • 2021-07-06
相关资源
相似解决方案