1.实例化一个线程对象
1 Thread t = new Thread(); 2 t.setName("甲");
2.实例化一个线程对象的同时,通过构造方法对线程进行命名
1 Thread(Runnable r, String name) 2 Thread t = new Thread(() -> {}, "甲");
3.使用自定义的线程类,在实例化线程对象的同时,进行名称的赋值
1 MyThread t = new MyThread("甲"); 2 3 class MyThread extends Thread{ 4 5 public MutliTread(String name) { 6 this.setName(name); 7 //super(name) 8 } 9 public void run() {...} 10 }
原文地址:https://www.cnblogs.com/ggrrbb/p/12289693.html
时间: 2024-11-05 02:27:23