public class MyThread extends Thread {
public MyThread() {
}
public MyThread(String name) {
super(name);
}
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
可以,创建带参数的thread 构造函数,将传参传递给父类去给线程命名;
import java.nio.file.SecureDirectoryStream;
public class Demo01Thread {
public static void main(String[] arg) {
MyThread mt = new MyThread();
mt.setName("fang");
mt.start();
MyThread mt2 = new MyThread("fang2");
mt2.start();
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)