public class MyThread extends Thread {
public MyThread(String name) {
super(name);
System.out.println("ThreadName构造器");
System.out.println("this.getName() ="+this.getName());
System.out.println("Thread.currentThread().getName() ="+Thread.currentThread().getName());
}
@Override
public void run() {
System.out.println("ThreadName运行中");
System.out.println("this.getName() ="+this.getName());
System.out.println("Thread.currentThread().getName() ="+Thread.currentThread().getName());
}
public static void main(String[] args) {
MyThread runthread = new MyThread("runthread");
Thread reallyThread = new Thread(runthread,"reallyThread");
reallyThread.start();
}
}
结果:
ThreadName构造器
this.getName() =runthread
Thread.currentThread().getName() =main
ThreadName运行中
this.getName() =runthread
Thread.currentThread().getName() =reallyThread