日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

設(shè)置線(xiàn)程名稱(chēng)(兩種方法)

作者:Qiddo 更新時(shí)間: 2023-12-12 編程語(yǔ)言

方式一:通過(guò)構(gòu)造方法設(shè)置線(xiàn)程名稱(chēng)。

class SetName1 extends Thread{
  public SetName1(String name){
    super(name);
   }
  @Override
  public void run() {
    System.out.println(this.getName());
   }
}
public class SetNameThread {
  public static void main(String[] args) {
    SetName1 setName1 = new SetName1("SetName1");
    setName1.start();
   }
}

方式二:通過(guò)setName()方法設(shè)置線(xiàn)程名稱(chēng)。

class SetName2 implements Runnable{
  @Override
  public void run() {
    System.out.println(Thread.currentThread().getName());
   }
}
public class SetNameThread {
  public static void main(String[] args) {
    Thread thread = new Thread(new SetName2());
    thread.setName("SetName2");
    thread.start();
   }
}

原文鏈接:https://blog.csdn.net/m0_73944607/article/details/130609104

  • 上一篇:沒(méi)有了
  • 下一篇:沒(méi)有了
欄目分類(lèi)
最近更新