Thread 介绍

Thread 类是非常重要的线程类,它实现了Runnable接口,可以开启一个 Java 线程。

使用示例

class MyThread extends Thread{
    private String name ; 
    public MyThread(String name){
        this.name = name ;
    }

    public void run(){
        for(int i=0;i<10;i++){
            System.out.println(name + "运行,i = " + i) ;
        }
    }
};

public class Test {
    public static void main(String args[]){
        MyThread mt1 = new MyThread("线程A ") ;
        MyThread mt2 = new MyThread("线程B ") ;
        mt1.start() ;
        mt2.start() ;
    }
};

相关文章:

  • 2021-08-19
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2021-04-10
  • 2021-09-09
  • 2021-11-01
  • 2022-12-23
猜你喜欢
  • 2021-12-20
  • 2021-12-07
  • 2022-12-23
  • 2021-12-07
  • 2021-04-12
  • 2021-06-25
相关资源
相似解决方案