为什么小弟我的线程被修改了名字

为什么我的线程被修改了名字?

class MyThread extends Thread
{
MyThread(String st)
{
super(st);
}

public void run()
{
String st = "我的线程ID为: " + this.getId() + "\n" +
      "我的名字是: " + this.getName() + "\n" +
"目前线程数为: " + this.activeCount() + "\n" +
"我的优先级为: " + this.getPriority() + "\n" +
"我的状态是: " + this.getState() + "\n" ;

System.out.print(st);
}
}

public class CreateThread1
{
public static void main(String[] args)
{
MyThread th = new MyThread("周黑鸭");

th.start();

th.setName("喵菜头");
th.setPriority(10);

th.run();

}
}
为什么小弟我的线程被修改了名字

为什么我先设置了线程名字为“周黑鸭”
线程的优先级为10

但是两次显示 都显示的修改后的线程结果?
------解决方案--------------------
因为你下面调用了setName方法,覆盖了构造方法里面的名字,想知道setName方法怎么传递参数的,你去看下源码,一看就直到怎么回事了
------解决方案--------------------
public class CreateThread1 {
public static void main(String[] args) throws InterruptedException {
MyThread th = new MyThread("周黑鸭");

th.start();
Thread.sleep(2000);
th.setName("喵菜头");
th.setPriority(10);

th.run();

}
}

你那样写,第一个线程还没打印"我的名字是: " + this.getName(); 就已经执行接下来的代码th.setName("喵菜头"); 为什么小弟我的线程被修改了名字

------解决方案--------------------
这样写法的结果,第一个打印的内容存在随机性,两种可能性都有。第二个任何时候都只会打印喵菜头
------解决方案--------------------
这个可以不用线程的思维来考虑
Thread类有个属性name,你开始你赋值给他"周黑鸭"
然后又setName("喵菜头");那这个name属性已经变成"喵菜头"了

况且线程还没run()

------解决方案--------------------
这就是start和run的差别了吧。start是异步的得等cpu调度才能执行,run就是对象方法直接调用了。